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

Sign XML and add a prefix

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
1 7528
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Holger Joukl | last post by:
Hi there, 2 questions regarding build/installation issues: 1. In the python 2.3.3 setup.py script, the detect_modules method of class PyBuildExt contains the following code: 253 if...
29
by: Mark Hahn | last post by:
We are considering switching to the dollar sign ($) for self, instead of the period ( . ) we are using now in Prothon. Ruby uses the at-sign (@) for self, but our new usage of self also includes...
3
by: Jacques | last post by:
I'm experiencing the following problem The source xml file uses a prefix (wpl:) and look like this (shortened): ----------------------------------------------------------------- <?xml...
4
by: Krishna Tulasi via .NET 247 | last post by:
Hi, I am having trouble with creation of XML programmatically using .NET. Specifically Im trying to create an element which looks like below and insert into an existing xml doc: <Worksheet...
3
by: Ken Durden | last post by:
Is it possible to force positive values to have the + sign prefixed on them? double f1 = 1024.2; double f2 = -1024.2; string.Format( "{0:F}", f1 ); // +1024.2 string.Format( "{0:F}", f2 );...
4
by: BizTalk Benjamin | last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
8
by: subramanian100in | last post by:
Consider int i = 10; Why do we say that ++i yields an Lvalue and i++ yields an Rvalue ? I thought both these expressions yield only values. I am unable to understand the difference
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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.