This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
javax.crypto.BadPaddingException: Given final block not properly padded
Kevin P Smith
Ranch Hand
Joined: Feb 18, 2005
Posts: 362
posted
0
Hi
Wondering if anyone can help me with what appears to be an intermintent problem with decrypting database data...
I am using teh below (snippets) code to encrypt users' private data to store in a database, then decrypt so they can view it.
To encrypt:
I have read around the forums and most people seem to say it's because when converting the bytes to a String the encrypted data becomes compromised, but I can
not see any other way in which I can handle this encrypted data and pass it to the database then back again.
Any suggestions?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
You shouldn't use "new String(...)" and "String.getBytes()" to perform the conversion - that implies the data is character data, which simply isn't the case. The easiest would probably be to use base-64 to convert a byte[] into a string; the Apache Commons Codec library can do that.
Cheers for that, the following code seems to be working, although I haven't fully tested it (don't know if I dare incase I get another 'random' exception!)
Shital Joshi
Greenhorn
Joined: Jun 30, 2010
Posts: 9
posted
0
Ulf Dittmer wrote:You shouldn't use "new String(...)" and "String.getBytes()" to perform the conversion - that implies the data is character data, which simply isn't the case. The easiest would probably be to use base-64 to convert a byte[] into a string; the Apache Commons Codec library can do that.
i tried the same, but the conversion i am not being able to perform, it gives me error that " Access restriction: BASE64Decoder() " , what to do?
i have all jar files even rt.jar and jce.jar also
please help me out, i facing problem in decryption