0

I am trying to decrypt email id and get this exception. My encryption is successfully but while decryption i get this.

Caused by: javax.crypto.BadPaddingException: pad block corrupted at org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:715) at javax.crypto.Cipher.doFinal(Cipher.java:1090)

Help Appreciated

user755499
  • 2,241
  • 4
  • 25
  • 34
  • 1
    I don't know what error you are facing. look at this http://stackoverflow.com/questions/8357868/how-do-i-securely-store-encryption-keys-in-java/8358023#8358023 – Padma Kumar Dec 05 '11 at 15:11
  • Thanks @padma-kumar for the pointers read my comment below – user755499 Dec 06 '11 at 09:56

1 Answers1

1

Either the ciphertext has become corrupted, or you are not using the same block size or padding to decrypt as was used to encrypt.

Can you show us the code you're using to encrypt and decrypt?

Qwerky
  • 18,217
  • 6
  • 44
  • 80
  • 1
    Thanks @qwerky for the pointers i read those i found that in my code i had these lines for encryption SecretKeySpec skeySpec = new ecretKeySpec(someKey, "AES/CBC/PKCS5Padding"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); AND while decrypting i was decrypting in wrong way like this SecretKeySpec skeySpec = new SecretKeySpec(rawKey, "AES"); Cipher cipher = Cipher.getInstance("AES");. I missed this "AES/CBC/PKCS5Padding" in the getInstance() method. Thanks guys. – user755499 Dec 06 '11 at 09:56