• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!)

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Let me tell you a story about a man named Jed. He made this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic