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!

Problem decrypting data with OAEP padding using BC

843811Jul 26 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2008
Added on Jul 26 2008
0 comments
1,748 views