NoSuchAlgorithmException: No provider found for SM4

System.err: cn.hutool.crypto.CryptoException: NoSuchAlgorithmException: No provider found for SM4
System.err:     at cn.hutool.crypto.SecureUtil.createCipher(SecureUtil.java:987)
System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.init(SymmetricCrypto.java:154)
System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.(SymmetricCrypto.java:124)
System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.(SymmetricCrypto.java:112)
System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.(SymmetricCrypto.java:101)
System.err:     at cn.hutool.crypto.symmetric.SM4.(SM4.java:37)

 

Sm4加解密,遇到如上的问题,在网上搜了很多资料,乱改一通,跟着添加
compile 'org.bouncycastle:bcpg-jdk16:1.46'

及代码添加

Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
Security.addProvider(new BouncyCastleProvider());

出现新问题:

System.err: cn.hutool.crypto.CryptoException: NoSuchAlgorithmException: Provider BC does not provide SM4
System.err:     at cn.hutool.crypto.SecureUtil.createCipher(SecureUtil.java:987)
com.reach.covid W/System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.init(SymmetricCrypto.java:154)
com.reach.covid W/System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.(SymmetricCrypto.java:124)
com.reach.covid W/System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.(SymmetricCrypto.java:112)
com.reach.covid W/System.err:     at cn.hutool.crypto.symmetric.SymmetricCrypto.(SymmetricCrypto.java:101)
com.reach.covid W/System.err:     at cn.hutool.crypto.symmetric.SM4.(SM4.java:37)
com.reach.covid W/System.err:     at cn.hutool.crypto.SmUtil.sm4(SmUtil.java:143)

还是没有解决!!!!

查阅了很多外国资料,抱着试一试的态度,居然好了。。。。。

解决方法是版本原因!

implementation 'cn.hutool:hutool-all:5.4.5'
compile 'org.bouncycastle:bcprov-jdk15to18:1.69'

版本更新至这样就行了。。。。以此记录下这问题,em........

你可能感兴趣的:(Android,java,jvm,sum4,AES,加解密)