473,654 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Security .Cryptography.R SA.ToXmlString - Key not valid for use in specified state

Hello,

I am trying to run a .NET 2.0 application that I developed and I am
getting the following error:

Key not valid for use in specified state

I am attempting to retrieve the X509Certificate 2.PrivateKey as an XML
string via the ToXmlString() function and this error occurs. Below is
an example of the command line call that I used to make my test
certificate.

Using makecert in the following manner:
"C:\Program Files\Microsoft Visual Studio
8\Common7\Tools \Bin\makecert.e xe" -r -pe -n "CN=TestCertifi cate" -b
01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3 .1 -ss my -sr localMachine
-sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
TestCertificate .cer

I have no problem making the call of the ToXmlString() function on my
development machine, which is where I constructed the certificate, but
when I export the certificate from my development machine and import
onto a test machine, I get the "Key not valid for use in specified
state" error message on the test machine. I made sure to export my
private key, and I am even using the Microsoft WSE 3.0 Certificate Tool
to verify that the private key has been properly exported to the test
machine. I even made sure that the user attempting to access the
private key has the proper access permissions.
Below is the stack trace that I am getting when calling the ToXmlString
function
STACK TRACE:
at
System.Security .Cryptography.C ryptographicExc eption.ThrowCry ptographicEx
ception(Int32 hr)
at System.Security .Cryptography.. utils._ExportKe y(SafeKeyHandle hKey,
Int32 blobType, Object cspObject)
at
System.Security .Cryptography.R SACryptoService Provider.Export Parameters(B
oolean includePrivateP arameters)
at System.Security .Cryptography.R SA.ToXmlString( Boolean
includePrivateP arameters)

Any help on this would be greatly appreciated. Thanks in advance.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 15 '07 #1
1 12506
In my case, when I imported the certificate into the key store I did
not select the Mark as Exportable option. This is necessary to access
to private key.
Eric Simmons escreveu:
Hello,

I am trying to run a .NET 2.0 application that I developed and I am
getting the following error:

Key not valid for use in specified state

I am attempting to retrieve the X509Certificate 2.PrivateKey as an XML
string via the ToXmlString() function and this error occurs. Below is
an example of the command line call that I used to make my test
certificate.

Using makecert in the following manner:
"C:\Program Files\Microsoft Visual Studio
8\Common7\Tools \Bin\makecert.e xe" -r -pe -n "CN=TestCertifi cate" -b
01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3 .1 -ss my -sr localMachine
-sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
TestCertificate .cer

I have no problem making the call of the ToXmlString() function on my
development machine, which is where I constructed the certificate, but
when I export the certificate from my development machine and import
onto a test machine, I get the "Key not valid for use in specified
state" error message on the test machine. I made sure to export my
private key, and I am even using the Microsoft WSE 3.0 Certificate Tool
to verify that the private key has been properly exported to the test
machine. I even made sure that the user attempting to access the
private key has the proper access permissions.
Below is the stack trace that I am getting when calling the ToXmlString
function
STACK TRACE:
at
System.Security .Cryptography.C ryptographicExc eption.ThrowCry ptographicEx
ception(Int32 hr)
at System.Security .Cryptography.. utils._ExportKe y(SafeKeyHandle hKey,
Int32 blobType, Object cspObject)
at
System.Security .Cryptography.R SACryptoService Provider.Export Parameters(B
oolean includePrivateP arameters)
at System.Security .Cryptography.R SA.ToXmlString( Boolean
includePrivateP arameters)

Any help on this would be greatly appreciated. Thanks in advance.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4948
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
0
3542
by: Andrzej | last post by:
Hi, I have to figure out why we have a problem with special characters in encrypted usernames and passwords. Case: Username: r&bgeorge Password: tigger
3
11464
by: segue | last post by:
I have VS 2005, .NET 2.0, no girlfriend and this article: http://msdn2.microsoft.com/en-us/library/ms278836.aspx. Yet, I can't successfully import this namespace. System.Security.Cryptography.Xml. error message:
1
2759
by: muthu | last post by:
Hi, I have two web applications running on my machine.The application is developed using asp.net 1.1 and vb.net.When i try to run both the applications in the same browsers, i get the following error. (System.Security.Cryptography.CryptographicException: Bad Data. at System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr hKey, Byte rgb, Int32 ib, Int32 cb, Boolean fDone) at...
1
1176
by: Abhi | last post by:
Hi I have built an application that uses Cryptography Application block 2.0, It runs fine on my machine. Now i copy this application the complete debug folder along with .config and .key file to another machine.It does not Run. It gives error as "Key not valid for running in specified state". I know this error is coming because the key has been created on my machine and is not valid for that machine, so how do i create a generic key...
1
2245
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
Hi, everybody here. I am implementing data encryption/decryption, and try to use System.Security.Cryptography.TripleDESCryptoServiceProvider. But I can not find it in MS Visual Studio when I wrote code like (C#) using System.Security.Cryptography.TripleDESCryptoServiceProvider; Under System.Security.Cryptography, only have X509Certificates.
6
6296
by: andrew | last post by:
Hi, I have a web service application written in C# .NET 1.1 using MD5CryptoServiceProvider.ComputeHash(Byte) The problem is that after a while(web service processes requests) the call throws CryptographicException "the parameter is incorrect" Here's the stack trace: System.Security.Cryptography.CryptographicException: The parameter is
0
3360
by: Amelyan | last post by:
Why does this happen? How to fix it? Once in a while I get error in ~/ScriptResource.axd?d=... System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at
8
13330
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service and hosted it in Windows Services. It is working fine. Now I am trying to implement the X509 certificates for message layer security. But it is throwing the following exception: An unhandled exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll
0
8379
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8709
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...
0
8596
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
7309
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...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1924
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.