This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Security and the fly likes Exception while decrypting data org.bouncycastle.crypto.InvalidCipherTextException: pad block corrup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Exception while decrypting data org.bouncycastle.crypto.InvalidCipherTextException: pad block corrup" Watch "Exception while decrypting data org.bouncycastle.crypto.InvalidCipherTextException: pad block corrup" New topic
Author

Exception while decrypting data org.bouncycastle.crypto.InvalidCipherTextException: pad block corrup

Mike Newmann
Greenhorn

Joined: Mar 22, 2013
Posts: 1
Hi,

I am trying to use BouncyCastle LightWeight API for AES 256 bit decryption, but I am getting an exception while trying to decrypt the data.

Following is my code:-


----------------------------- My main class -----------------------------





----------------------------- AESEncDec.java -----------------------------







org.bouncycastle.crypto.InvalidCipherTextException: pad block corrupted
at org.bouncycastle.crypto.paddings.PKCS7Padding.padCount(PKCS7Padding.java:63)
at org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher.doFinal(PaddedBufferedBlockCipher.java:287)



Really need some help on this.. have been stuck with it for the whole day and have no idea what is it that's going wrong.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

If you are certain that correct padding is being used then based on experience I suspect the key you are using is not the one used to encrypt the data. A key mismatch still allows basic decryption but the resulting padding will be invalid.

Of course if one had a view of the code used to encrypt then one might be able to give a more definite diagnosis.
 
Consider Paul's rocket mass heater.
 
subject: Exception while decrypting data org.bouncycastle.crypto.InvalidCipherTextException: pad block corrup
 
Similar Threads
Problem encrypting with openssl, decrypting with bouncy castle
AES decryption problem
Bouncycastle AES - output isn't the same as input!
AES Encryption Service
TripleDES compatibility (Sun - BC)