472,794 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

SignedXML

Hello,
I'm trying to create signed XML document with SignedXml class. As a
SigningKey I'd like to use key pair obtained from user certificate
stored in current user certificate store. I'm using WSE 2 SP 2 to get
certificate, but when I'm invoking ComputeSignature() method of
SignedXML instance I recive the following exception:

"An unhandled exception of type 'System.NotSupportedException'
occurred in microsoft.web.services2.dll

Additional information: DecryptValue"

I'd also like to mention, that when I try to export key's parameters I
recive the following exception:
"An unhandled exception of type 'System.NotSupportedException'
occurred in microsoft.web.services2.dll

Additional information: Export of private parameters is not supported"

User certificate was created with Windows 2003 Enterprice Edition's
CertSrv.
I've tryed to create certificate with and without checked "Mark keys
as exportable" and the result is the same.

What can be wrong?

Here is code listing:

// Create example data to sign.
XmlDocument document = new XmlDocument();
XmlNode node = document.CreateNodeXmlNodeType.Element, "",
"MyElement", "samples");

node.InnerText = "This is some text";
document.AppendChild(node);

// Get user certificate
X509CertificateStore store = new
X509CertificateStore(X509CertificateStore.StorePro vider.System,
X509CertificateStore.StoreLocation.CurrentUser,
X509CertificateStore.MyStore);

store.Open();
X509Certificate xCert = store.Certificates[0];
store.Close();

// Create the SignedXml message.
SignedXml signedXml = new SignedXml();
RSA key = xCert.Key;
//RSA key = RSA.Create();
//key.ImportParameters(xCert.Key.ExportParameters(tr ue));
signedXml.SigningKey = key;

// Create a data object to hold the data to sign.
DataObject dataObject = new DataObject();
dataObject.Data = document.ChildNodes;
dataObject.Id = "MyObjectId";

// Add the data object to the signature.
signedXml.AddObject(dataObject);

// Create a reference to be able to package everything into the
// message.
Reference reference = new Reference();
reference.Uri = "#MyObjectId";

// Add it to the message.
signedXml.AddReference(reference);

// Add a KeyInfo.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue(key));
signedXml.KeyInfo = keyInfo;

// Compute the signature.
signedXml.ComputeSignature();
Thanks for your replay - Karol.
Nov 12 '05 #1
4 4943
Raj
Karol,
I can see either one of the two issues

1. Your private Key is not part of the certificate

2. If you still believe that, the private key is present as part of the
certificate, try using Microsoft.Web.Services.Security.X509.X509Certifica te
object for retrieving the Certificate from the store by using
(X509CertificateStore available in the same package).I was able to implement
it without any problem using this class and was having some issues with the
WSE2 classes

X509Certificate.Key will give u the private key

Hope it helps
Thanks
Raj

"Karol" wrote:
Hello,
I'm trying to create signed XML document with SignedXml class. As a
SigningKey I'd like to use key pair obtained from user certificate
stored in current user certificate store. I'm using WSE 2 SP 2 to get
certificate, but when I'm invoking ComputeSignature() method of
SignedXML instance I recive the following exception:

"An unhandled exception of type 'System.NotSupportedException'
occurred in microsoft.web.services2.dll

Additional information: DecryptValue"

I'd also like to mention, that when I try to export key's parameters I
recive the following exception:
"An unhandled exception of type 'System.NotSupportedException'
occurred in microsoft.web.services2.dll

Additional information: Export of private parameters is not supported"

User certificate was created with Windows 2003 Enterprice Edition's
CertSrv.
I've tryed to create certificate with and without checked "Mark keys
as exportable" and the result is the same.

What can be wrong?

Here is code listing:

// Create example data to sign.
XmlDocument document = new XmlDocument();
XmlNode node = document.CreateNodeXmlNodeType.Element, "",
"MyElement", "samples");

node.InnerText = "This is some text";
document.AppendChild(node);

// Get user certificate
X509CertificateStore store = new
X509CertificateStore(X509CertificateStore.StorePro vider.System,
X509CertificateStore.StoreLocation.CurrentUser,
X509CertificateStore.MyStore);

store.Open();
X509Certificate xCert = store.Certificates[0];
store.Close();

// Create the SignedXml message.
SignedXml signedXml = new SignedXml();
RSA key = xCert.Key;
//RSA key = RSA.Create();
//key.ImportParameters(xCert.Key.ExportParameters(tr ue));
signedXml.SigningKey = key;

// Create a data object to hold the data to sign.
DataObject dataObject = new DataObject();
dataObject.Data = document.ChildNodes;
dataObject.Id = "MyObjectId";

// Add the data object to the signature.
signedXml.AddObject(dataObject);

// Create a reference to be able to package everything into the
// message.
Reference reference = new Reference();
reference.Uri = "#MyObjectId";

// Add it to the message.
signedXml.AddReference(reference);

// Add a KeyInfo.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue(key));
signedXml.KeyInfo = keyInfo;

// Compute the signature.
signedXml.ComputeSignature();
Thanks for your replay - Karol.

Nov 12 '05 #2
If your using WSE, why are you also using SignedXML? You could instead just
sign the soap body with your token and WSE handles all that. Unless I miss
something (which is likely.)

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Karol" <re***@tlen.pl> wrote in message
news:c8*************************@posting.google.co m...
Hello,
I'm trying to create signed XML document with SignedXml class. As a
SigningKey I'd like to use key pair obtained from user certificate
stored in current user certificate store. I'm using WSE 2 SP 2 to get
certificate, but when I'm invoking ComputeSignature() method of
SignedXML instance I recive the following exception:

"An unhandled exception of type 'System.NotSupportedException'
occurred in microsoft.web.services2.dll

Additional information: DecryptValue"

I'd also like to mention, that when I try to export key's parameters I
recive the following exception:
"An unhandled exception of type 'System.NotSupportedException'
occurred in microsoft.web.services2.dll

Additional information: Export of private parameters is not supported"

User certificate was created with Windows 2003 Enterprice Edition's
CertSrv.
I've tryed to create certificate with and without checked "Mark keys
as exportable" and the result is the same.

What can be wrong?

Here is code listing:

// Create example data to sign.
XmlDocument document = new XmlDocument();
XmlNode node = document.CreateNodeXmlNodeType.Element, "",
"MyElement", "samples");

node.InnerText = "This is some text";
document.AppendChild(node);

// Get user certificate
X509CertificateStore store = new
X509CertificateStore(X509CertificateStore.StorePro vider.System,
X509CertificateStore.StoreLocation.CurrentUser,
X509CertificateStore.MyStore);

store.Open();
X509Certificate xCert = store.Certificates[0];
store.Close();

// Create the SignedXml message.
SignedXml signedXml = new SignedXml();
RSA key = xCert.Key;
//RSA key = RSA.Create();
//key.ImportParameters(xCert.Key.ExportParameters(tr ue));
signedXml.SigningKey = key;

// Create a data object to hold the data to sign.
DataObject dataObject = new DataObject();
dataObject.Data = document.ChildNodes;
dataObject.Id = "MyObjectId";

// Add the data object to the signature.
signedXml.AddObject(dataObject);

// Create a reference to be able to package everything into the
// message.
Reference reference = new Reference();
reference.Uri = "#MyObjectId";

// Add it to the message.
signedXml.AddReference(reference);

// Add a KeyInfo.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue(key));
signedXml.KeyInfo = keyInfo;

// Compute the signature.
signedXml.ComputeSignature();
Thanks for your replay - Karol.


Nov 12 '05 #3
Raj <Ra*@discussions.microsoft.com> wrote in message news:<BA**********************************@microso ft.com>...
Karol,
I can see either one of the two issues

1. Your private Key is not part of the certificate

2. If you still believe that, the private key is present as part of the
certificate, try using Microsoft.Web.Services.Security.X509.X509Certifica te
object for retrieving the Certificate from the store by using
(X509CertificateStore available in the same package).I was able to implement
it without any problem using this class and was having some issues with the
WSE2 classes

X509Certificate.Key will give u the private key


Thanks Raj,
Retriving Certificate and it's Key with WSE 1.0 solved the problem :)

--
Best regards,
Karol
Nov 12 '05 #4

Thanks Raj,
Retriving Certificate and it's Key with WSE 1.0 solved the problem
:)

--
Best regards,
Karol [/b]


Karol Hi !!

Could you post some sample code of the corrected and working solution
??

I'm dealing wit the same problem at this moment.

Thank you very much.

El Bruno

--
ElBruno
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message1415408.html

Nov 12 '05 #5

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

Similar topics

5
by: Raghu | last post by:
I am using SignedXml class to sign and verify soap xml documents. We are not using WSE at this point. When I sign a soap document and send it to my trading partner, they can verify the document...
7
by: Guangxi Wu | last post by:
Hi all, Happy New Year. I am using SignedXML and an X509 certificate to digitally sign a SOAP message body and put the signature in the SOAP header for a B2B business application. Can you...
0
by: pak76 | last post by:
Class SignedXml is used to produce/verify signature over XML document. One of its methods, function GetIdElement, is used to select Xml elements for signature and verification and consist following...
0
by: ChrisA | last post by:
I'm using Michael Gallants DecodeCertKey example to get the public key from an X509 certificate. I then create an RSAServiceProvider and try to use it to CheckSignature() on the signed XML file....
2
by: Nikhil | last post by:
When I try to used the CheckSignature Method of SignedXML I get the following error. "Unknown transform has been encountered. at System.Security.Cryptography.Xml.Reference.LoadXml(XmlElement...
2
by: William Stacey [MVP] | last post by:
Given the following, how do I get the plain xml without the security elements (i.e. the original xml before the security was added) in the VerifyXML() method. TIA. using System; using...
2
by: Rune Nergard | last post by:
I have tried to use the System.Security.Cryptography.Xml.SignedXml class to sign an Xml message with Xml-DSIG and using an Enveloped signature type and the sha1RSA algorithm. Everything works fine...
1
by: Peter Ravnholt | last post by:
Hello all, It seems that digitally signing XML documents using the SignedXml class has a bug - or at least a behavior I cannot explain. The problem occurs when I sign XML documents containing...
0
by: Iguana | last post by:
Hi! Im creating project in c# .net2.0, to sign and verify documens us xmldsig format. My problem is how to use prefix "ds" instead of: xmlns="http://www.w3.org/2000/09/xmldsig#" in SignedInfo,...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.