473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

"object already exists" exception using RSACryptoServiceProvider

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
2 5967
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
My email application was working a couple of weeks ago, then all of a sudden I get Error Type: (0x8009000F) Object already exists. I checked the permissions on the machinekeys directory...
0
by: JenC | last post by:
Hi, I have a problem when I try to access a DLL I have created. Basically I have an application which uses a number of custom DLLs, I needed to amend one of the DLLs, so I removed the specific...
1
by: Uttam | last post by:
Hello, How does one suppress the "Object already exists" message when the following statement is executed in ADO? cat.Views.Append "Some_Query", cmd Thanks in advance. Uttam
7
by: (Pete Cresswell) | last post by:
We were testing a version of our app that's been running for months with no problems and it started throwing "Object no longer exists" messages on two machines in the test environment. We tried...
4
by: Liz Patton | last post by:
Here's the exception: System.Exception: Unable to send mail: Could not access 'CDO.Message' object. ---> System.Web.HttpException: Could not access 'CDO.Message' object. --->...
2
by: prince -=nore=- | last post by:
I have a page, where I'm retrieving a file location from a database and outputting it's contents (HTML) onto a web page. On the aspx page, I have referred to the code behind it using the line...
1
by: dwasler | last post by:
Try every thing I know to remove this alias I know there been other posting I read each one none seem to work. Thank You DLWasler dwasler@yahoo.com OS Window db2 V 8.2.X
1
by: atishrg | last post by:
Hello all, I am facing a problem,, that I am not able to trace a "OBJECT REFERENCE NOT SET TO AN INSTANCE OF AN OBJECT" EXCEPTION .... as I am using On error goto _Lable as soon as this...
2
by: bips2008 | last post by:
The code seems to work fine in other browser but in IE it throws this error. This is very urgent for me and any help would be greatly appreciated For your convienence i have posted the code for the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.