Problem decrypting data with OAEP padding using BC
All,
I am relatively new to java cryptography so please bare with me it you guys think this is a very basic question.
I am using 2048 bit RSAES-OAEP algorithm with ECB mode and SHA-256 hash to encrypt/decrypt my data. I've used sun's JCE to encrypt the data and trying to use BC's implementation to decrypt same data, which gives me following exception:
"javax.crypto.BadPaddingException: data hash wrong"
at org.bouncycastle.jce.provider.JCERSACipher.engineDoFinal(Unknown Source)
at javax.crypto.Cipher.doFinal(DashoA13*..)
Here's my code snippet:
Security.addProvider(bcp);
/* if I use following line, the decryption works fine and I get my original data back */
//Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA256AndMGF1Padding", bcp); cipher.init(Cipher.DECRYPT_MODE, privateKey); byte[] plaintext = cipher.doFinal(toDecrypt); return new String(plaintext, "UTF8");
please note that the I can decrypt the same date using the native JCE (shown in commented code).
I'll appreciate if I can get some help in this.
Thx
-Utkarsh