aspose file tools*
The moose likes Tomcat and the fly likes javax.crypto.BadPaddingException when trying to run AES enryption and decryption multiple times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Reply locked New topic
Author

javax.crypto.BadPaddingException when trying to run AES enryption and decryption multiple times

Mridul Dinakar
Greenhorn

Joined: Feb 22, 2012
Posts: 3
I am trying to encrypt and decrypt a message(String) using a given key string. For that, two seperate methods (one for encrypt and the other for decrypt) were called and when these methods are called from my applicaion. I am getting the below exception while decrypting. The encryption and decryption operations are working properly for the first time.Again if I call the methods with different message and key value it is throwing the below exception.

Exception:
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
at javax.crypto.Cipher.doFinal(Cipher.java:2086)

I don't think that, there is a problem with data. Because using the same data (key and message) when I try to call the encrypt/decrypt methods it is working properly. Also if I call the methods from my application for the first time, it will work fine. Please help me to solve the issue......

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

Please UseOneThreadPerQuestion. Let's continue here.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.crypto.BadPaddingException when trying to run AES enryption and decryption multiple times
 
Similar Threads
Help please: Encrypt, save to file, then decrypt later to read
Need help in password Encryption and Decryption
BadPaddingException with DES
Help please: Encrypt, save to file, then decrypt later to read
BadpaddingException