我在使用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重新启动后,错误消失,并在1或2天后再次出现。
BC罐没有被动过手脚。
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语言
- 雄猫6
- WEB-INF/lib文件夹中的bcprov-jdk15on-153.jar文件
- jce 6无限强度
我错过了什么吗?
1条答案
按热度按时间rjee0c151#
谢谢你@埃克斯,这为我指明了正确的方向,即使我没有遇到这个问题,因为我码头化的一切几年前。
另请参阅https://stackoverflow.com/a/9911395