473,387 Members | 1,569 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,387 software developers and data experts.

System.Security.Cryptography.RSA.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 X509Certificate2.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.exe" -r -pe -n "CN=TestCertificate" -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.CryptographicExceptio n.ThrowCryptographicEx
ception(Int32 hr)
at System.Security.Cryptography..utils._ExportKey(Saf eKeyHandle hKey,
Int32 blobType, Object cspObject)
at
System.Security.Cryptography.RSACryptoServiceProvi der.ExportParameters(B
oolean includePrivateParameters)
at System.Security.Cryptography.RSA.ToXmlString(Boole an
includePrivateParameters)

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

*** Sent via Developersdex http://www.developersdex.com ***
Jun 15 '07 #1
1 12472
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 X509Certificate2.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.exe" -r -pe -n "CN=TestCertificate" -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.CryptographicExceptio n.ThrowCryptographicEx
ception(Int32 hr)
at System.Security.Cryptography..utils._ExportKey(Saf eKeyHandle hKey,
Int32 blobType, Object cspObject)
at
System.Security.Cryptography.RSACryptoServiceProvi der.ExportParameters(B
oolean includePrivateParameters)
at System.Security.Cryptography.RSA.ToXmlString(Boole an
includePrivateParameters)

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
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...
0
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
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. ...
1
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...
1
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...
1
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...
6
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...
0
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...
8
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.