SecretKeyFactory, Cipher Blocking threads, degrading performance
843811Aug 22 2009 — edited Aug 23 2009Hi all,
I need urgent help. PLease send your suggestions. I have written following code snippet for AES encry/decry for PBE.
Class AES {
SecretKeyFactory factory = null;
static {
factory = SecretKeyFactory.getInstance("AES");
}
public static String encryt(String pass, String text) {
SecureRandom ran = ....;
bytes[] salt = ran.nextBytes();
PBESpecKey key factory.generateSecret(.....) ;
Cipher ciper = Cipher.getInstance("AES");
ciper.init(ENCRYPT);
bytes = ciper.doFinal(....);
return encryptedString;
}
public static String decryt(String salt, String encText) {
PBESpecKey key factory.generateSecret(salt, ......) ;
Cipher ciper = Cipher.getInstance("AES");
ciper.init(DECRYPT);
bytes = ciper.doFinal(....);
return decryptedString;
}
}
Please note that above syntax may not be correct. But in essence, I am using JCE classes for AES encryption decryption.
Problem
Since i started using above code, my all web applications threads are blocking in JCE classes. Application performance has gone down signifacntly. PLease suggest if above is the correct use of JCE classes. What alternative approach I can use?
Is it safe to use JCE classes in multi threaded applications? Memory usage was also extremely high.
Thanks and Regards
Chetan