It's not a secret anymore!*
The moose likes Java in General and the fly likes RSA decryption, BadPaddingException: Data must start with zero Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "RSA decryption, BadPaddingException: Data must start with zero" Watch "RSA decryption, BadPaddingException: Data must start with zero" New topic
Author

RSA decryption, BadPaddingException: Data must start with zero

Andreas Pax Lück
Greenhorn

Joined: Nov 04, 2009
Posts: 18
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:



"Wenn man irgendwann mal von allen akzeptiert wird, dann weiß man, dass man irgendwas falsch gemacht hat."
Excerpt by: Mr. Weidner
Andreas Pax Lück
Greenhorn

Joined: Nov 04, 2009
Posts: 18
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
Marshal

Joined: Mar 22, 2005
Posts: 41106
    
  45
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.


Ping & DNS - my free Android networking tools app
Andreas Pax Lück
Greenhorn

Joined: Nov 04, 2009
Posts: 18
ok, thanks ulf.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RSA decryption, BadPaddingException: Data must start with zero
 
Similar Threads
encryption decryption
signer information does not match? Help...
Have a problem when encrypt by RSA
RSA Cipher
Digital Signature in PKCS 7 format with base 64 encoding