javax.crypto.BadPaddingException: Data must start with zero
843811Aug 28 2006 — edited Nov 26 2008Hello,
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