By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,839 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,839 IT Pros & Developers. It's quick & easy.

"object already exists" exception using RSACryptoServiceProvider

P: n/a
Hello everyone.

I have a small class that encapsulates some functionallity to work with the
RSACryptoServiceProvider. Here is the code of the class i'm using:

public class dsRSA
{
private RSACryptoServiceProvider objRSA = null;

public dsRSA(string keyContainerName)
{
CspParameters csp = new CspParameters();
csp.Flags = CspProviderFlags.UseMachineKeyStore;
csp.KeyContainerName = keyContainerName;
objRSA = new RSACryptoServiceProvider(1024, csp);
}
// other code goes here that i'm not using at
this point
}

My app is calling the following code when a winform loads:

private dsRSA _rsa;
_rsa = new dsRSA("ABACUS");

as you can see i'm only instatiating de RSACryptoServiceProvider with the
keyContainerName as a parameter passed by my app.. so when execution of the
code reaches the line "objRSA = new RSACryptoServiceProvider(1024, csp);" i
get the following error:

CryptographicException: "object already exists"

StackTrace " en
System.Security.Cryptography.CryptographicExceptio n.ThrowCryptogaphicException(Int32
hr)\r\n en System.Security.Cryptography.Utils._CreateCSP(CspP arameters
param, Boolean randomKeyContainer, SafeProvHandle& hProv)\r\n en
System.Security.Cryptography.Utils.CreateProvHandl e(CspParameters parameters,
Boolean randomKeyContainer)\r\n en
System.Security.Cryptography.Utils.GetKeyPairHelpe r(CspAlgorithmType keyType,
CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize,
SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der.GetKeyPair()\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der..ctor(Int32 dwKeySize,
CspParameters parameters, Boolean useDefaultKeySize)\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der..ctor(Int32 dwKeySize,
CspParameters parameters)\r\n en DescaCryp.dsRSA..ctor(String
keyContainerName) en F:\\ProyectosC#\\DescaCryp\\RSA.cs:lÃ*nea 24\r\n en
KeyFileGenerator.frmKeyGen..ctor() en C:\\Gabriel\\Desca\\ABACUS\\ABACUS
2.1\\Codigo ABACUS\\KeyFileGenerator\\frmKeyGen.cs:lÃ*nea 51" string
The app have just worked fine for some time, and is still working on other
machines, but suddenly stopped worked on my developing machine.. Does anyone
know what is causing this execption and how to solve it??

Note: If i change the keyContainerName parameter, it works ok... it seems to
be a restriction or something i need to release when the app closes...

Thanks
Feb 5 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pbx
On Feb 5, 7:10 am, Gabriel Méndez
<GabrielMn...@discussions.microsoft.comwrote:
Hello everyone.

I have a small class that encapsulates some functionallity to work with theRSACryptoServiceProvider. Here is the code of the class i'm using:

public class dsRSA
{
privateRSACryptoServiceProviderobjRSA = null;

public dsRSA(string keyContainerName)
{
CspParameters csp = new CspParameters();
csp.Flags = CspProviderFlags.UseMachineKeyStore;
csp.KeyContainerName = keyContainerName;
objRSA = newRSACryptoServiceProvider(1024, csp);
}

// other code goes here that i'm not using at
this point

}

My app is calling the following code when a winform loads:

private dsRSA _rsa;
_rsa = new dsRSA("ABACUS");

as you can see i'm only instatiating deRSACryptoServiceProviderwith the
keyContainerName as a parameter passed by my app.. so when execution of the
code reaches the line "objRSA = newRSACryptoServiceProvider(1024, csp);" i
get the following error:

CryptographicException: "objectalreadyexists"

StackTrace " enSystem.Security.Cryptography.CryptographicExcept ion..ThrowCryptogaphicExcept*ion(Int32
hr)\r\n en System.Security.Cryptography.Utils._CreateCSP(CspP arameters
param, Boolean randomKeyContainer, SafeProvHandle& hProv)\r\n en
System.Security.Cryptography.Utils.CreateProvHandl e(CspParameters parameters,
Boolean randomKeyContainer)\r\n en
System.Security.Cryptography.Utils.GetKeyPairHelpe r(CspAlgorithmType keyType,
CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize,
SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der.GetKeyPair()\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der..ctor(Int32 dwKeySize,
CspParameters parameters, Boolean useDefaultKeySize)\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der..ctor(Int32 dwKeySize,
CspParameters parameters)\r\n en DescaCryp.dsRSA..ctor(String
keyContainerName) en F:\\ProyectosC#\\DescaCryp\\RSA.cs:línea 24\r\n en
KeyFileGenerator.frmKeyGen..ctor() en C:\\Gabriel\\Desca\\ABACUS\\ABACUS
2.1\\Codigo ABACUS\\KeyFileGenerator\\frmKeyGen.cs:línea 51" string

The app have just worked fine for some time, and is still working on other
machines, but suddenly stopped worked on my developing machine.. Does anyone
know what is causing this execption and how to solve it??

Note: If i change the keyContainerName parameter, it works ok... it seemsto
be a restriction or something i need to release when the app closes...

Thanks
Are you running on Vista? I am having the same problem.

Mar 6 '07 #2

P: n/a
Nop... i'm currently having that error my laptop running Windows XP SP2
--
Ing. Gabriel Méndez
MCP, MCAD
"pbx" wrote:
On Feb 5, 7:10 am, Gabriel Méndez
<GabrielMn...@discussions.microsoft.comwrote:
Hello everyone.

I have a small class that encapsulates some functionallity to work with theRSACryptoServiceProvider. Here is the code of the class i'm using:

public class dsRSA
{
privateRSACryptoServiceProviderobjRSA = null;

public dsRSA(string keyContainerName)
{
CspParameters csp = new CspParameters();
csp.Flags = CspProviderFlags.UseMachineKeyStore;
csp.KeyContainerName = keyContainerName;
objRSA = newRSACryptoServiceProvider(1024, csp);
}

// other code goes here that i'm not using at
this point

}

My app is calling the following code when a winform loads:

private dsRSA _rsa;
_rsa = new dsRSA("ABACUS");

as you can see i'm only instatiating deRSACryptoServiceProviderwith the
keyContainerName as a parameter passed by my app.. so when execution of the
code reaches the line "objRSA = newRSACryptoServiceProvider(1024, csp);" i
get the following error:

CryptographicException: "objectalreadyexists"

StackTrace " enSystem.Security.Cryptography.CryptographicExcept ion..ThrowCryptogaphicExceptÂ*ion(Int32
hr)\r\n en System.Security.Cryptography.Utils._CreateCSP(CspP arameters
param, Boolean randomKeyContainer, SafeProvHandle& hProv)\r\n en
System.Security.Cryptography.Utils.CreateProvHandl e(CspParameters parameters,
Boolean randomKeyContainer)\r\n en
System.Security.Cryptography.Utils.GetKeyPairHelpe r(CspAlgorithmType keyType,
CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize,
SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der.GetKeyPair()\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der..ctor(Int32 dwKeySize,
CspParameters parameters, Boolean useDefaultKeySize)\r\n en
System.Security.Cryptography.RSACryptoServiceProvi der..ctor(Int32 dwKeySize,
CspParameters parameters)\r\n en DescaCryp.dsRSA..ctor(String
keyContainerName) en F:\\ProyectosC#\\DescaCryp\\RSA.cs:lÃ*nea 24\r\n en
KeyFileGenerator.frmKeyGen..ctor() en C:\\Gabriel\\Desca\\ABACUS\\ABACUS
2.1\\Codigo ABACUS\\KeyFileGenerator\\frmKeyGen.cs:lÃ*nea 51" string

The app have just worked fine for some time, and is still working on other
machines, but suddenly stopped worked on my developing machine.. Does anyone
know what is causing this execption and how to solve it??

Note: If i change the keyContainerName parameter, it works ok... it seems to
be a restriction or something i need to release when the app closes...

Thanks

Are you running on Vista? I am having the same problem.

Mar 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.