Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javax.crypto.BadPaddingException: Data must start with zero

843811Aug 28 2006 — edited Nov 26 2008
Hello,

I saw that a lot of other developers have the same problem but I did not find my solution in posted messages.

I'm getting RSA encrypted data from an external device and I have to decrypt it with the private key.
Code I use to decode is the following:
------------------------------------------------------------

private String decodeCryptedData(String szData){
String szDecodedData ="";

try{
Cipher decrypt = Cipher.getInstance("RSA");
//Cipher decrypt = Cipher.getInstance("RSA/ECB/PKCS1Padding");
decrypt.init(Cipher.DECRYPT_MODE, privateKeyRSA);

byte[] decodeData= decrypt.doFinal(szData.getBytes("ISO-8859-1"));
szDecodedData = new String(decodeData, "ISO-8859-1");


}catch(Exception ex){
log.error("Exception occured in function decodeCryptedData: " + ex);
return "";
}

return szDecodedData ;

}

------------------------------------------------------------

When using this code I get the exception : javax.crypto.BadPaddingException: Data must start with zero

As you can see I tried with "RSA" an also "RSA/ECB/PKCS1Padding" but the result is always the same.
I'm now looking for a solution on internet for 8 hours but I cannot find it.
Does anyone of you has an idea?

Thanks in advance.

Alain.

null
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 24 2008
Added on Aug 28 2006
23 comments
4,720 views