Re: Another RSACryptoServiceProvider question
From: Pieter Philippaerts (Pieter_at_nospam.mentalis.org)
Date: 10/29/03
- Previous message: Andrew Edward: "Re: DPAPI or not DPAPI, that is the question"
- In reply to: Daryn Kiely: "Another RSACryptoServiceProvider question"
- Next in thread: Daryn Kiely: "Re: Another RSACryptoServiceProvider question"
- Reply: Daryn Kiely: "Re: Another RSACryptoServiceProvider question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 29 Oct 2003 20:49:43 +0100
"Daryn Kiely" <anonymous@discussions.microsoft.com> wrote in message
> This works great if the fOAEP flag is
> false (use PKCS padding) but fails if I use OAEP
> padding. In both cases the encryption works, but in the
> latter case the code throws a Cryptographic Exception
> with the message "Error occured while decoding OAEP
> padding".
There are two problems with your code. The first is that you use the
rsaEncrypt object to both encrypt and decrypt. rsaEncrypt.Decrypt will
obviously not work because it doesn't have access to the private key.
However I assume it was an error in your post and not an error in the code
you're using because you said PKCS#1 worked.
Secondly, you're trying to encrypt/decrypt too many bytes. If you change the
number of bytes you're trying to encrypt to 86, everything works perfectly.
This is in accordance with the MSDN documentation, that states "Modulus
size -2 -2*hLen, where hLen is the size of the hash". If you take modulus
size to be 128 bytes [or 1024 bits] and hLen 20 bytes [ie. SHA-1], you get
128 - 2 - 2 * 20 = 86.
It's strange that the encrypt method works and the decrypt doesn't. The
encrypt method should have thrown an exception.
Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
- Previous message: Andrew Edward: "Re: DPAPI or not DPAPI, that is the question"
- In reply to: Daryn Kiely: "Another RSACryptoServiceProvider question"
- Next in thread: Daryn Kiely: "Re: Another RSACryptoServiceProvider question"
- Reply: Daryn Kiely: "Re: Another RSACryptoServiceProvider question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|