signing a xml document with x509 certificate

How does the server know what certificate the document is signed with? You seem to not to include the cert in the signed document:

    KeyInfo keyInfo = new KeyInfo();
    KeyInfoX509Data keyInfoData = new KeyInfoX509Data( Key );
    keyInfo.AddClause( keyInfoData );
    signedXml.KeyInfo = keyInfo;

If you need more details, consult my blog entry

http://www.wiktorzychla.com/2012/12/interoperable-xml-digital-signatures-c_20.html


It's a long time since this post has been created. I got the same problem with the digital signature can not be validated.

For whom who has the same issue. In my case the difference is XmlDocument.PreserveWhitespace option.

When the PreserveWhitespace = true, the document is not valid when checking against the public key. PreserveWhitespace = false makes the signed XML valid.

I guess that when saving the signed XML to file and sending it to server. There is some space or special characters are inserted to the document and make it invalid.