Howdy,
I'm trying to sign some XML and then verify the signature. I used an example from this great article on signing XML with X509Certificates:
http://msdn.microsoft.com/msdnmag/issues/04/11/XMLSignatures/
Now I'm trying to verify the signature and CheckSignature is always returning false. I've tried a few different methods with no success. The certificiate I used for ths signing was loaded from a PFX file and the CA for that certificate is in my trusted root store.
Here is the code I'm using for the verification:
private bool VerifyCert(X509Certificate2 cert, XmlDocument doc){
bool verified = false;
SignedXml sxml = new SignedXml(doc);
XmlNodeList xmllist = doc.GetElementsByTagName("Signature");
sxml.LoadXml((XmlElement)(xmllist[0]));
verified = sxml.CheckSignature(cert, true);
return verified;
}
"cert" is an X509Certificate2 object that I loaded with the following code:
XmlNodeList nodes = doc.GetElementsByTagName("X509Certificate");string base64Cert;
XmlNode node = nodes[0];
base64Cert = node.InnerText;
byte[] certBytes = Convert.FromBase64String(base64Cert);
verified = VerifyCert(new X509Certificate2(certBytes), doc);
I read some other posts about this and tried using another CheckSignature overload and got the same false result. I used the public key object and also tried creating a new RSA object using FromXmlString(). Neither worked
verified = sxml.CheckSignature(cert.PublicKey.Key);
Am I missing anything here It all looks like it should work.
Thanks,
-d

CheckSignature on SignedXml with X509Certificate