在我的带有 BC 类的 WebApps 上一段时间后,我遇到了 NoClassDefFoundError:
java.lang.NoClassDefFoundError: org/bouncycastle/util/Pack
at org.bouncycastle.crypto.engines.AESFastEngine.unpackBlock(Unknown Source)
at org.bouncycastle.crypto.engines.AESFastEngine.processBlock(Unknown Source)
at org.bouncycastle.crypto.modes.CBCBlockCipher.decryptBlock(Unknown Source)
at org.bouncycastle.crypto.modes.CBCBlockCipher.processBlock(Unknown Source)
at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.processBytes(Unknown Source)
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$BufferedGenericBlockCipher.processBytes(Unknown Source)
at org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineUpdate(Unknown Source)
at javax.crypto.Cipher.update(DashoA13*..)...
重启tomcat后,错误消失,过一两天又出现。
BC jar 没有被篡改。
BC是这样注册和使用的:
// registration
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null)
{
Security.addProvider(new BouncyCastleProvider());
}
SecretKey secretKey = new SecretKeySpec("_mykey__mykey__mykey__mykey__myk".getBytes(), "AES");
IvParameterSpec iv = new IvParameterSpec("_iv__iv__iv__iv_".getBytes());
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
System.out.println(cipher.getProvider()); // prints "BC version 1.53"
// encryption
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
cipher.update("clearContent".getBytes());
byte[] cipheredContent = cipher.doFinal();
// decryption
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
cipher.update(cipheredContent);
byte[] clearContent = cipher.doFinal();
System.out.println(new String(clearContent)); // prints "clearContent"
这里是组件:
- Java 6
- Tomcat 6
- WEB-INF/lib文件夹下的bcprov-jdk15on-153.jar
- jce6无限力量
我错过了什么吗?
最佳答案
谢谢@eckes,这为我指明了正确的方向,即使自从几年前我对所有内容进行 docker 化以来我就没有遇到过这个问题。
关于java - BouncyCaSTLe 类上的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34881126/