在使用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"
以下是组件:
我错过了什么吗?