• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

RSA decryption, BadPaddingException: Data must start with zero

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friends!

i have got a problem with RSA en-/decryption. following simple example uses the public key from the keypair for encryption, and the private key for decryption. sometimes it works and sometimes there's a badpaddingexcpetion trown. i searched the internet about this problem but didn't find any working solution. perhaps, this is bug? i hope you can help me. here comes the code:

 
Andreas Pax Lück
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
alright, guys.

i tried to use a byte array for the message (not string) and now it works. this helps me. but do you have any idea why the string conversion destroys the encryption?

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Encrypted stuff is binary data, not character data, so it can't be meaningfully converted to a String. If for some reason you need an ASCII representation of something that's encrypted (maybe for storing it in a text-only database field), then you should run it through an encoding like base-64.
 
Andreas Pax Lück
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, thanks ulf.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic