By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,208 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,208 IT Pros & Developers. It's quick & easy.

Sign XML and add a prefix

P: n/a
I am experimenting with the Cryptography API (using c#). I have
successfully managed to sign some XML using an RSA algorithm. I can
then vaidate the XML with a Verify method that I have developed.

I am using the SignedXML class to generate the signed XML. I would
like the output XML to use the prefix "ds" for elements within the
"http://www.w3.org/2000/09/xmldsig#" namespace.

I have searched long and hard but cannot find any information on how
to do this. It seems a reasonable thing to do as a lot of non
microsoft applications seem to produce the signed XML using this
prefix.

I don't really want to have to modify the XML after it has been signed
to add these prefixes. Can anyone help?

Below is the method that I am using to sign the XML:

================================================== ============================

public string Sign(string strXML, RSACryptoServiceProvider rsa)
{
// Create the SignedXml message.
SignedXml xmlSign = new SignedXml();
// Set the RSA key for signing.
xmlSign.SigningKey = rsa;

// Create a Reference to point to the to-be-signed content.
Reference reference = new Reference();

XmlDocument doc = new XmlDocument();

DataObject obj = new DataObject();
doc.LoadXml (strXML);
obj.Data = doc.ChildNodes;
obj.Id = "MyObjectId";
reference.Uri = "#" + "MyObjectId";
xmlSign.AddObject(obj);

// Add the Reference to the SignedXml message.
xmlSign.AddReference(reference);

// Add a KeyInfo element to the SignedXml message.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)rsa));
xmlSign.KeyInfo = keyInfo;

// Compute the XML Digital Signature.
xmlSign.ComputeSignature();
return xmlSign.GetXml().OuterXml;
}
Nov 11 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You can try to add attribute xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
to doc.DocumentElement.
Sergey
--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Rich" <ri*****@penrose.me.uk> wrote in message
news:e2**************************@posting.google.c om...
I am experimenting with the Cryptography API (using c#). I have
successfully managed to sign some XML using an RSA algorithm. I can
then vaidate the XML with a Verify method that I have developed.

I am using the SignedXML class to generate the signed XML. I would
like the output XML to use the prefix "ds" for elements within the
"http://www.w3.org/2000/09/xmldsig#" namespace.

I have searched long and hard but cannot find any information on how
to do this. It seems a reasonable thing to do as a lot of non
microsoft applications seem to produce the signed XML using this
prefix.

I don't really want to have to modify the XML after it has been signed
to add these prefixes. Can anyone help?

Below is the method that I am using to sign the XML:

================================================== ==========================
==
public string Sign(string strXML, RSACryptoServiceProvider rsa)
{
// Create the SignedXml message.
SignedXml xmlSign = new SignedXml();
// Set the RSA key for signing.
xmlSign.SigningKey = rsa;

// Create a Reference to point to the to-be-signed content.
Reference reference = new Reference();

XmlDocument doc = new XmlDocument();

DataObject obj = new DataObject();
doc.LoadXml (strXML);
obj.Data = doc.ChildNodes;
obj.Id = "MyObjectId";
reference.Uri = "#" + "MyObjectId";
xmlSign.AddObject(obj);

// Add the Reference to the SignedXml message.
xmlSign.AddReference(reference);

// Add a KeyInfo element to the SignedXml message.
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)rsa));
xmlSign.KeyInfo = keyInfo;

// Compute the XML Digital Signature.
xmlSign.ComputeSignature();
return xmlSign.GetXml().OuterXml;
}

Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.