Another RSACryptoServiceProvider question
From: Daryn Kiely (anonymous_at_discussions.microsoft.com)
Date: 10/29/03
- Next message: Andrew Edward: "Re: DPAPI or not DPAPI, that is the question"
- Previous message: Panga Tc: "Re: CAPI - crypt and decrypt using public/private key pairs"
- Next in thread: Pieter Philippaerts: "Re: Another RSACryptoServiceProvider question"
- Reply: Pieter Philippaerts: "Re: Another RSACryptoServiceProvider question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 29 Oct 2003 10:54:31 -0800
I have a simple little test program (see below) that
encrypts an array of bytes and turns around and decrypts
the same array. 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". What am I missing here?!?!?! Oh, the code is
using the certificate store provided by Mentalis.org...
byte [] indata;
byte [] outdata;
byte [] encrypteddata = null;
CertificateStore cs = new CertificateStore("MY");
Certificate cert = cs.FindCertificateBySubjectString("R&D
Client");
RSACryptoServiceProvider rsaDecrypt =
(RSACryptoServiceProvider) cert.PrivateKey;
RSACryptoServiceProvider rsaEncrypt =
(RSACryptoServiceProvider) cert.PublicKey;
Console.WriteLine("Crypto Algorithm
{0}",rsaEncrypt.SignatureAlgorithm);
Console.WriteLine("Key Exchange Algorithm
{0}",rsaEncrypt.KeyExchangeAlgorithm);
indata = new byte[87];
for (int i = 0; i != indata.Length; i++)
{
indata[i] = Convert.ToByte(i%255);
}
try
{
encrypteddata = rsaEncrypt.Encrypt(indata, true);
}
catch (CryptographicException ce)
{
Console.WriteLine("Crypto Exception
{0}",ce.Message);
Console.WriteLine("Stack: {0}",ce.StackTrace);
}
try
{
outdata = rsaEncrypt.Decrypt(encrypteddata, true);
}
catch (CryptographicException ce)
{
Console.WriteLine("Crypto Exception {0}, size =
{1}",ce.Message);
}
- Next message: Andrew Edward: "Re: DPAPI or not DPAPI, that is the question"
- Previous message: Panga Tc: "Re: CAPI - crypt and decrypt using public/private key pairs"
- Next in thread: Pieter Philippaerts: "Re: Another RSACryptoServiceProvider question"
- Reply: Pieter Philippaerts: "Re: Another RSACryptoServiceProvider question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|