Santos_6556
Jun 02, 2009Nimbostratus
Encrypt with AES::encrypt but, how to decrypt with Java?
Hello.
With Java, you must get a Cypher:
Cipher decryptCipher = Cipher.getInstance("AES");
decryptCipher.init(Cipher.DECRYPT_MODE, getSecretKey());
byte[] deciphertext = decryptCipher.doFinal(encripted);
String decryptedString = new String(deciphertext);
But this code causes this error:
javax.crypto.IllegalBlockSizeException: 9 trailing bytes
at gnu.javax.crypto.jce.cipher.CipherAdapter.engineDoFinal(libgcj.so.90)
at javax.crypto.Cipher.doFinal(libgcj.so.90)
at javax.crypto.Cipher.doFinal(libgcj.so.90)
The problem is with PADDING, but I don't know exactly where does the problem is.
When I get the Cipher, I can choose with diferent options:
Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
Cipher decryptCipher = Cipher.getInstance("AES/CFB8/NoPadding");
...
Maybe the problem is I don't get the good Cipher.
Can anybody help me?
Thanks.