2
Reply

RSACryptoServiceProvider exception

Tom

Tom

Feb 7 2007 3:13 AM
3.6k

Hi,

I've been using the CspParameter class to read/write RSA parameters that is used for encrypting data.

private string Encrypt(string plainText)
{
    try
    {
        CspParameters cp = new CspParameters();
        cp.KeyContainerName = "RSAKeyContainer";
        RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp); <<< exception occurs here
        RSAParameters RSAParams = rsa.ExportParameters(false);
        return RSAEncrypt(plainText, RSAParams, false);
    }
    catch (CryptographicException e)
    {
        return "";
    }
}

The code has been working fine, but recently it started throwing an exception
when I try to instantiate the RSACryptoServiceProvider class. Changing the
KeyContainerName worked for a while, but then the problem came back again.
The error message is "Object already exists". Can anyone explain what's going on ?


Answers (2)