From: Gabriel Méndez on 5 Feb 2007 10:10 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.CryptographicException.ThrowCryptogaphicException(Int32 hr)\r\n en System.Security.Cryptography.Utils._CreateCSP(CspParameters param, Boolean randomKeyContainer, SafeProvHandle& hProv)\r\n en System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)\r\n en System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n en System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()\r\n en System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)\r\n en System.Security.Cryptography.RSACryptoServiceProvider..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
From: pbx on 5 Mar 2007 19:53 On Feb 5, 7:10 am, Gabriel Méndez <GabrielMn...(a)discussions.microsoft.com> wrote: > 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.CryptographicException..ThrowCryptogaphicException(Int32 > hr)\r\n en System.Security.Cryptography.Utils._CreateCSP(CspParameters > param, Boolean randomKeyContainer, SafeProvHandle& hProv)\r\n en > System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, > Boolean randomKeyContainer)\r\n en > System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, > CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, > SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n en > System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()\r\n en > System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, > CspParameters parameters, Boolean useDefaultKeySize)\r\n en > System.Security.Cryptography.RSACryptoServiceProvider..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.
|
Pages: 1 Prev: More detailed information about Exception Error? Next: Custom Configuration - dll |