File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.crypto.BadPaddingException: Given final block not properly padded

 
Kevin P Smith
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kevin P Smith
Ranch Hand
Posts: 362
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic