File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RSA decryption, BadPaddingException: Data must start with zero

 
Andreas Pax Lück
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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?

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks ulf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic