I have NoClassDefFoundError after some time on my WebApps with BC classes:
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*..)...
After a tomcat restart, the error disappears and reappears after 1 or 2 days.
The BC jar hasn't been tampered with.
BC is registered and used like this :
// 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"
Here are the components :
- java 6
- tomcat 6
- bcprov-jdk15on-153.jar in the WEB-INF/lib folder
- jce6 unlimited strength
Am I missing something ?
ServletContextListener.contextInitialized(ServletContextEvent event)
– neomega