Xml document signature not valid after deserialization from byte array Xml document signature not valid after deserialization from byte array xml xml

Xml document signature not valid after deserialization from byte array


@formatc I don´t have privileges to comment, but can you try and view the hexadecimal values in both files (sign and deserialized). I had the same problem, for some reason in my case when constructing back the xml some non-visual characters are inserted in front of the document. You won´t see them unless you use HexView or some tool like that.

I was able to remove those characters programmatically and all went well.


  • Be sure their array character longs for the case are they equal? before the validation you must see some differencies.
  • Also, some Signture technics can use any inner sign prefixes like a GUID, control them.

Use Utf8 on both


i had exactly the same issue as you have. signature was valid but references not. the problem is (at least in my case), that serialization and deserialization can affect the content of the xml. in my case it helped to call document.normalizeDocument() before signing the document and now the signature validates even after serialization/deserialization.