I am trying to sign Xml (actually SOAP xml) in C # using the SignedXml class , the signing step is successful, but when I try to verify the signature that tells me that it is not valid. The only change I made from the example on MSDN was that I used XmlDsigExcC14NTransform instead of the XmlDsigEnvelopedSignatureTransform conversion. If I use XmlDsigEnvelopedSignatureTransform, I will get a valid signature.
Here is my code for signing:
private static XmlDocument SignXml(XmlDocument doc) { SignedXml signedXml = new SignedXml(doc); signedXml.SigningKey = Certificate.PrivateKey; Reference reference = new Reference(); reference.Uri = ""; XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
The code above will give me a valid signature, but if I use
XmlDsigExcC14NTransform env = new XmlDsigExcC14NTransform();
instead
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
I will receive an invalid signature.
Here is my confirmation code:
private static bool Verify(XmlDocument doc) { SignedXml signedDoc = new SignedXml(doc); XmlNodeList nodeList = doc.GetElementsByTagName(Constants.SignatureElement); signedDoc.LoadXml((XmlElement)nodeList[0]); return signedDoc.CheckSignature((RSA)Certificate.PublicKey.Key); }
Can someone tell me how I can sign with the conversion algorithm http://www.w3.org/2001/10/xml-exc-c14n#
Thanks in advance.
source share