android 使用BouncyCastle
网址:
https://square.github.io/retrofit/
https://github.com/square/retrofit/
https://www.jianshu.com/p/81754adcd4ae
android jdk8使用
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
报异常:
java.security.NoSuchAlgorithmException: Provider BC does not provide SM4/CBC/PKCS5Padding
generateSm4EcbCipher 替换成它
private Cipher generateSm4EcbCipher(String sm4Name, int sm4Mode, byte[] sm4Key) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException { // Cipher cipher = Cipher.getInstance(sm4Name, BouncyCastleProvider.PROVIDER_NAME); Cipher cipher = Cipher.getInstance(sm4Name, new BouncyCastleProvider()); Key secretKey = new SecretKeySpec(sm4Key, SM4_NAME); IvParameterSpec ivParameterSpec = new IvParameterSpec(SM4_KEY_IV); try { cipher.init(sm4Mode, secretKey, ivParameterSpec); } catch (InvalidKeyException | InvalidAlgorithmParameterException e) { e.printStackTrace(); } return cipher; }