473,320 Members | 2,112 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,320 software developers and data experts.

How to canonicalize an XML Document

Hi

I previously posted a question which hasn't been answered, so I figured
it must have been too complicated. I must admit that I didn't make it
very easy to follow. In fact, the information I need is quite simple.
How to canonicalize an XML Document in C#? Consider the following code:

XmlDocument myDoc = new XmlDocument();
myDoc.Load("somefile.xml");
XmlDsigC14NTransform t = new XmlDsigC14NTransform();
t.LoadInput (myDoc);
Stream s = (Stream) t.GetOutput(typeof(Stream));
SHA1 sha1 = SHA1.Create();

byte[] hash = sha1.ComputeHash(s);
Does s represent a stream of a canonicalized document?
Nov 12 '05 #1
1 9436
"Pollux" <po****@nospam.spam> wrote in message news:MP************************@usenet.plus.net...
XmlDocument myDoc = new XmlDocument();
myDoc.Load("somefile.xml");
XmlDsigC14NTransform t = new XmlDsigC14NTransform();
t.LoadInput (myDoc);
Stream s = (Stream) t.GetOutput(typeof(Stream)); : : Does s represent a stream of a canonicalized document?


Yes.

You can examine the document in s with,

Console.WriteLine( new StreamReader( s).ReadToEnd( ));

Note the Java code posed in your original post used the following
canonicalization method,

http://www.w3.org/TR/2001/REC-xml-c1...5#WithComments

which corresponds to the XmlDsigC14NWithCommentsTransform
class. This only impacts you if "something.xml" contains comments,
otherwise the two canonicalizations are the same. In your particular
case this difference doesn't apply to this document (because you're
selecting the Body to sign and your sample document had no
comments within the Body), but you should use the right Transform
so that you can successfully verify the signatures on instance docs
that do have comments.
Derek Harmon
Nov 12 '05 #2

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

Similar topics

1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
2
by: Edward | last post by:
The below code builds 2 tables 4 rows by 4 cols. All cells have checkboxes. When checked, the checkboxes in the first column automatically check the remainder of the check boxes in the same row. ...
1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
4
by: Oleg Subachev | last post by:
I need to canonicalize (in the sence of http://www.w3.org/TR/xml-c14n) some input XML and get canonicalized output XML. How can I perform this under .NET ? -- Oleg Subachev
0
by: Pollux | last post by:
Hi, I'm having a problem canonicalizing an xml document and getting a hash that matches that of an existing document so I was wondering if somebody knew what I was doing wrong. I generate an...
0
by: Martin Silar | last post by:
Hi, I canonicalize document subset and result is different from w3c.org examples. Do you know where is the problem? thanks Martin String xPath="(//. | //@* | //namespace::*)"; ...
1
by: Pollux | last post by:
Hi I previously posted a question which hasn't been answered, so I figured it must have been too complicated. I must admit that I didn't make it very easy to follow. In fact, the information I...
0
by: Martin | last post by:
Hi, I canonicalize document subset and result is different from w3c.org examples. Do you know where is the problem? thanks Martin String xPath="(//. | //@* | //namespace::*)"; ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.