473,839 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"object already exists" exception using RSACryptoServic eProvider

Hello everyone.

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

public class dsRSA
{
private RSACryptoServic eProvider objRSA = null;

public dsRSA(string keyContainerNam e)
{
CspParameters csp = new CspParameters() ;
csp.Flags = CspProviderFlag s.UseMachineKey Store;
csp.KeyContaine rName = keyContainerNam e;
objRSA = new RSACryptoServic eProvider(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 RSACryptoServic eProvider with the
keyContainerNam e as a parameter passed by my app.. so when execution of the
code reaches the line "objRSA = new RSACryptoServic eProvider(1024, csp);" i
get the following error:

CryptographicEx ception: "object already exists"

StackTrace " en
System.Security .Cryptography.C ryptographicExc eption.ThrowCry ptogaphicExcept ion(Int32
hr)\r\n en System.Security .Cryptography.U tils._CreateCSP (CspParameters
param, Boolean randomKeyContai ner, SafeProvHandle& hProv)\r\n en
System.Security .Cryptography.U tils.CreateProv Handle(CspParam eters parameters,
Boolean randomKeyContai ner)\r\n en
System.Security .Cryptography.U tils.GetKeyPair Helper(CspAlgor ithmType keyType,
CspParameters parameters, Boolean randomKeyContai ner, Int32 dwKeySize,
SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\ r\n en
System.Security .Cryptography.R SACryptoService Provider.GetKey Pair()\r\n en
System.Security .Cryptography.R SACryptoService Provider..ctor( Int32 dwKeySize,
CspParameters parameters, Boolean useDefaultKeySi ze)\r\n en
System.Security .Cryptography.R SACryptoService Provider..ctor( Int32 dwKeySize,
CspParameters parameters)\r\n en DescaCryp.dsRSA ..ctor(String
keyContainerNam e) en F:\\ProyectosC# \\DescaCryp\\RS A.cs:lÃ*nea 24\r\n en
KeyFileGenerato r.frmKeyGen..ct or() en C:\\Gabriel\\De sca\\ABACUS\\AB ACUS
2.1\\Codigo ABACUS\\KeyFile Generator\\frmK eyGen.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 keyContainerNam e 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 6070
pbx
On Feb 5, 7:10 am, Gabriel Méndez
<GabrielMn...@d iscussions.micr osoft.comwrote:
Hello everyone.

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

public class dsRSA
{
privateRSACrypt oServiceProvide robjRSA = null;

public dsRSA(string keyContainerNam e)
{
CspParameters csp = new CspParameters() ;
csp.Flags = CspProviderFlag s.UseMachineKey Store;
csp.KeyContaine rName = keyContainerNam e;
objRSA = newRSACryptoSer viceProvider(10 24, 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 deRSACryptoServ iceProviderwith the
keyContainerNam e as a parameter passed by my app.. so when execution of the
code reaches the line "objRSA = newRSACryptoSer viceProvider(10 24, csp);" i
get the following error:

CryptographicEx ception: "objectalreadye xists"

StackTrace " enSystem.Securi ty.Cryptography .CryptographicE xception..Throw CryptogaphicExc ept*ion(Int32
hr)\r\n en System.Security .Cryptography.U tils._CreateCSP (CspParameters
param, Boolean randomKeyContai ner, SafeProvHandle& hProv)\r\n en
System.Security .Cryptography.U tils.CreateProv Handle(CspParam eters parameters,
Boolean randomKeyContai ner)\r\n en
System.Security .Cryptography.U tils.GetKeyPair Helper(CspAlgor ithmType keyType,
CspParameters parameters, Boolean randomKeyContai ner, Int32 dwKeySize,
SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\ r\n en
System.Security .Cryptography.R SACryptoService Provider.GetKey Pair()\r\n en
System.Security .Cryptography.R SACryptoService Provider..ctor( Int32 dwKeySize,
CspParameters parameters, Boolean useDefaultKeySi ze)\r\n en
System.Security .Cryptography.R SACryptoService Provider..ctor( Int32 dwKeySize,
CspParameters parameters)\r\n en DescaCryp.dsRSA ..ctor(String
keyContainerNam e) en F:\\ProyectosC# \\DescaCryp\\RS A.cs:línea 24\r\n en
KeyFileGenerato r.frmKeyGen..ct or() en C:\\Gabriel\\De sca\\ABACUS\\AB ACUS
2.1\\Codigo ABACUS\\KeyFile Generator\\frmK eyGen.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 keyContainerNam e 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...@d iscussions.micr osoft.comwrote:
Hello everyone.

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

public class dsRSA
{
privateRSACrypt oServiceProvide robjRSA = null;

public dsRSA(string keyContainerNam e)
{
CspParameters csp = new CspParameters() ;
csp.Flags = CspProviderFlag s.UseMachineKey Store;
csp.KeyContaine rName = keyContainerNam e;
objRSA = newRSACryptoSer viceProvider(10 24, 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 deRSACryptoServ iceProviderwith the
keyContainerNam e as a parameter passed by my app.. so when execution of the
code reaches the line "objRSA = newRSACryptoSer viceProvider(10 24, csp);" i
get the following error:

CryptographicEx ception: "objectalreadye xists"

StackTrace " enSystem.Securi ty.Cryptography .CryptographicE xception..Throw CryptogaphicExc eptÂ*ion(Int32
hr)\r\n en System.Security .Cryptography.U tils._CreateCSP (CspParameters
param, Boolean randomKeyContai ner, SafeProvHandle& hProv)\r\n en
System.Security .Cryptography.U tils.CreateProv Handle(CspParam eters parameters,
Boolean randomKeyContai ner)\r\n en
System.Security .Cryptography.U tils.GetKeyPair Helper(CspAlgor ithmType keyType,
CspParameters parameters, Boolean randomKeyContai ner, Int32 dwKeySize,
SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\ r\n en
System.Security .Cryptography.R SACryptoService Provider.GetKey Pair()\r\n en
System.Security .Cryptography.R SACryptoService Provider..ctor( Int32 dwKeySize,
CspParameters parameters, Boolean useDefaultKeySi ze)\r\n en
System.Security .Cryptography.R SACryptoService Provider..ctor( Int32 dwKeySize,
CspParameters parameters)\r\n en DescaCryp.dsRSA ..ctor(String
keyContainerNam e) en F:\\ProyectosC# \\DescaCryp\\RS A.cs:lÃ*nea 24\r\n en
KeyFileGenerato r.frmKeyGen..ct or() en C:\\Gabriel\\De sca\\ABACUS\\AB ACUS
2.1\\Codigo ABACUS\\KeyFile Generator\\frmK eyGen.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 keyContainerNam e 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
3639
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 like the KB article said it still doesn't work. Does have any ideas?
0
1431
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 Reference from the application, amended and rebuild the DLL and then added the reference back into the application. There was no need to amend the applications code as this was a very minor change. When I run the application I get the following:
1
4733
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
3422
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 the same test scenario on a production box: no problems. Tried them on my developer box: no problems. In each of those two cases, the PC's were connected to the same test server and *supposedly* had the same production build image on them. ...
4
3978
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. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80004005): Unspecified error --- End of inner exception stack trace ---
2
1635
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 below. This is where I'm getting the "Object reference not set to an instance.." error <% response.writefile(thelink())%>. The function that line is referring to is below. The record is being retrieved from the database according to its...
1
9971
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
2512
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 exception occures control directly shifted to error lable I want to excute next line even if this exception occures... Can Any one help to do this Atish
2
4317
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 file. The portion that is not working is the star rating part <?php session_start(); include_once('includes/host_conf.php'); include_once('includes/db_connect.php'); include_once('includes/mysql.lib.php');...
0
10914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10597
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10656
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10299
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7834
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.