android 报错 java.security.NoSuchAlgorithmException: Provider BC does not provide SM4/CBC/PKCS5Padding

转: https://blog.csdn.net/nodonoidea/article/details/119727242

java后台写法

    Cipher cipher = Cipher.getInstance(algorithmName, BouncyCastleProvider.PROVIDER_NAME);
    Key sm4Key = new SecretKeySpec(key, ALGORITHM_NAME);
    IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
    cipher.init(mode, sm4Key, ivParameterSpec);
    return cipher;

android 正确的使用BouncyCastleProvider

Cipher cipher = Cipher.getInstance(ALGORITHM_NAME_CBC_PADDING, new BouncyCastleProvider());
Key sm4Key = new SecretKeySpec(key, "SM4");
cipher.init(Cipher.ENCRYPT_MODE, sm4Key);
cipher.doFinal(plain);

如果安卓 使用BouncyCastleProvider.PROVIDER_NAME 就会报错。要使用new BouncyCastleProvider()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容