Home All Groups Group Topic Archive Search About

OAEP Decryption Error

Author
5 May 2005 3:33 PM
Sushant Bhatia
Hi All,

  Unwisely, I cross posted and it was bad. So i remove all the cross
posts and created a new single group post. Sorry about that google. So
here goes.

  I am trying to do encryption/decryption with RSA.

For encryption, I use the public key. For decryption, I use the private
key. The idea is to take a 80 byte array and encrypt it and then
decrypt that result to get the original 80 byte array. However, when I
do the decryption I am getting a "Error occurred while decoding OAEP
padding." CryptoGraphicException.

byte[] RSAResult = RSA.Encrypt(dataToDecrypt,true);

encryptedData = rsaCSP.Decrypt(dataToEncrypt, true);

I have tried using false for the OAEP parameter (all combinations) but
that only gets bad key or bad data exceptions. I looked on google and I
didn't find too much on this topic except an article suggesting having
the same size buffer which I did keep the same size.

The wierd thing is that I am doing the exact same piece of code at the
beginning of my program and it works. This code is called again in the
middle of my app and it fails. Too wierd.

Any ideas or suggestions?

Thanks guys.
Sushant Bhatia

Author
5 May 2005 3:56 PM
Valery Pryamikov
As I already told you - it does look like a bug in your code - try debugging
your program - some part of your code is either changing content of
encrypted buffer or resetting keys that you use.
I.e. when your code is called at the beginning of the program and works - it
operates with all correct values, but when you call it from the middle of
your program and it fails - it either trying to decrypt wrong data or using
wrong private key or both.

-Valery.
http://www.harper.no/valery

Show quoteHide quote
"Sushant Bhatia" <sushant.bha***@gmail.com> wrote in message
news:1115307195.085350.214650@g14g2000cwa.googlegroups.com...
> Hi All,
>
>  Unwisely, I cross posted and it was bad. So i remove all the cross
> posts and created a new single group post. Sorry about that google. So
> here goes.
>
>  I am trying to do encryption/decryption with RSA.
>
> For encryption, I use the public key. For decryption, I use the private
> key. The idea is to take a 80 byte array and encrypt it and then
> decrypt that result to get the original 80 byte array. However, when I
> do the decryption I am getting a "Error occurred while decoding OAEP
> padding." CryptoGraphicException.
>
> byte[] RSAResult = RSA.Encrypt(dataToDecrypt,true);
>
> encryptedData = rsaCSP.Decrypt(dataToEncrypt, true);
>
> I have tried using false for the OAEP parameter (all combinations) but
> that only gets bad key or bad data exceptions. I looked on google and I
> didn't find too much on this topic except an article suggesting having
> the same size buffer which I did keep the same size.
>
> The wierd thing is that I am doing the exact same piece of code at the
> beginning of my program and it works. This code is called again in the
> middle of my app and it fails. Too wierd.
>
> Any ideas or suggestions?
>
> Thanks guys.
> Sushant Bhatia
>