XmlStar usage in C#

50 Views Asked by At

I am trying to canonicalize a few xml documents. As I see it can be achieved by using XmlStar by executing a CMD command

xml c14n --exc-without-comments test_xml.xml > test_xml_canonicalize.xml

My question is can the same result be achieved with C# using XmlDsigC14NTransform class but without RSA signing and if so how?

1

There are 1 best solutions below

0
On

Solution:

     using (MemoryStream msIn = new MemoryStream(Encoding.UTF8.GetBytes(doc.InnerXml)))
     {
         var t = new XmlDsigExcC14NTransform(false);
         t.LoadInput(msIn);
         MemoryStream o = t.GetOutput() as MemoryStream;
         string c14N = Encoding.UTF8.GetString(o?.ToArray() ?? throw new InvalidOperationException());
         Console.WriteLine(c14N);
     }