Hi,
I need help in password encryption and decryption. I'm using DES Algorithm for encryption and decryption. It works well when I'm trying to encrypt and decrypt a
string . But I'm storing the encrypted string in the database. encryption works well. but when i tried to decrypt it is throwing some "BadPaddingException : Given final block not properly padded "..
Please help me..
Here is the code i used for decryption.
ecipher = Cipher.getInstance("DESede");
dcipher.init(Cipher.DECRYPT_MODE, key);
/*.......*/
public String decrypt(String str) {
try {
// Decode base64 to get bytes
byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
// Decrypt
byte[] utf8 = dcipher.doFinal(dec);
// Decode using utf-8
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (java.io.IOException e) {
}
return null;
}
Thanks in advance.
Regards,
Preethi.