赞
踩
报错详情:
Exception in thread "SpringThread-pool-pzj-5" Exception in thread "SpringThread-pool-pzj-10" java.lang.ExceptionInInitializerError at com.soc.cloud.iot.schedule.log.LogTaskContent.lambda$null$10(LogTaskContent.java:321) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: cn.hutool.crypto.CryptoException: NoSuchAlgorithmException: No such algorithm: SM4/ECB/PKCS5Padding at cn.hutool.crypto.SecureUtil.createCipher(SecureUtil.java:987) at cn.hutool.crypto.symmetric.SymmetricCrypto.init(SymmetricCrypto.java:154) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:124) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:112) at cn.hutool.crypto.symmetric.SymmetricCrypto.<init>(SymmetricCrypto.java:101) at com.soc.cloud.util.SM4Helper2.<clinit>(SM4Helper2.java:10) ... 4 more Caused by: java.security.NoSuchAlgorithmException: No such algorithm: SM4/ECB/PKCS5Padding at javax.crypto.Cipher.getInstance(Cipher.java:687) at cn.hutool.crypto.SecureUtil.createCipher(SecureUtil.java:985) ... 9 more Exception in thread "SpringThread-pool-pzj-6" Exception in thread "SpringThread-pool-pzj-4" Exception in thread "SpringThread-pool-pzj-2" java.lang.NoClassDefFoundError: Could not initialize class com.soc.cloud.util.SM4Helper2 at com.soc.cloud.iot.schedule.log.LogTaskContent.lambda$null$10(LogTaskContent.java:321) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) java.lang.NoClassDefFoundError: Could not initialize class com.soc.cloud.util.SM4Helper2 at com.soc.cloud.iot.schedule.log.LogTaskContent.lambda$null$10(LogTaskContent.java:321) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) java.lang.NoClassDefFoundError: Could not initialize class com.soc.cloud.util.SM4Helper2 at com.soc.cloud.iot.schedule.log.LogTaskContent.lambda$null$10(LogTaskContent.java:321) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) java.lang.NoClassDefFoundError: Could not initialize class com.soc.cloud.util.SM4Helper2 at com.soc.cloud.iot.schedule.log.LogTaskContent.lambda$null$10(LogTaskContent.java:321) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
源码:
import cn.hutool.crypto.SmUtil; import cn.hutool.crypto.symmetric.SymmetricCrypto; public class SM4Helper2 { //key必须是16字节,即128位 final static String key = "8464288604b7fc85"; //指明加密算法和秘钥 static SymmetricCrypto sm4 = new SymmetricCrypto("SM4/ECB/PKCS5Padding", key.getBytes()); // static SymmetricCrypto sm4 = SmUtil.sm4(key.getBytes()); //加密为16进制,也可以加密成base64/字节数组 public static byte[] encryptSm4(byte[] data) { byte[] encrypt = sm4.encrypt(data); return encrypt; } //解密 public static byte[] decryptSm4(byte[] data) { byte[] decrypt = sm4.decrypt(data); return decrypt; } }
解决办法:
maven应用的包版本不对:
bc包需要1.69版本的,下面这组坐标可以解决这个问题。
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.4.5</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15to18</artifactId>
<version>1.69</version>
</dependency>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。