XML Canonicalization algorithm gives two difference results when called directly than when called as part of an xml digital signature? XML Canonicalization algorithm gives two difference results when called directly than when called as part of an xml digital signature? xml xml

XML Canonicalization algorithm gives two difference results when called directly than when called as part of an xml digital signature?


The way in which XML Sig handles whitespace is, in my opinion broken. It's certainly not compliant with what most right-thinking people would call canonicalization. Changing whitespace should not affect the digest, but in xmlsig, it does.

One possible workaround is to pass the document through a canonicalizer routine before passing it to the signature generation code. That should make things far more predictable.

This article might help clarify things.


It looks like in your second piece of code you have

xmlDoc.PreserveWhitespace = true;

while in the first you do not.

As I understand it, the canonicalisation specification asks to preserve the whitespace between elements, so I suggest you include this line in both.