Skip to content

Instantly share code, notes, and snippets.

@roundand
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roundand/9910447 to your computer and use it in GitHub Desktop.
Save roundand/9910447 to your computer and use it in GitHub Desktop.
Demonstration of #XML #Canonicalisation in C# using #LinqPad
<Query Kind="Statements">
<Reference>&lt;RuntimeDirectory&gt;\System.Security.dll</Reference>
<Namespace>System.Security.Cryptography.Xml</Namespace>
</Query>
// need to load System.Security via F4
XmlDocument myDoc = new XmlDocument();
myDoc.LoadXml("<root x='x' a='a'><trunk>etc</trunk></root>");
myDoc.OuterXml.Dump("Attributes in original document order");
XmlDsigC14NTransform t = new XmlDsigC14NTransform();
t.LoadInput (myDoc);
var ms = (MemoryStream)t.GetOutput();
var x = Encoding.ASCII.GetString(ms.ToArray());
x.Dump("Attributes should be in alphabetical order");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment