我想对照计算机存储中的证书来验证SignedXml
中的签名。此代码用于验证签名:
internal bool VerifySignature(XmlDocument xml)
{
var signedXml = new SignedXml(xml);
var nsMgr = new XmlNamespaceManager(xml.NameTable);
nsMgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
signedXml.LoadXml((XmlElement)xml.SelectSingleNode("//ds:Signature", nsMgr));
return signedXml.CheckSignature();
}
签名可以很好地验证,但只能针对自身,而不能针对计算机上安装的证书。有没有办法根据本地证书存储中的根证书检查它?
最佳答案
如果有人感兴趣,我使用了CheckSignature(X509Certificate2, Boolean)
方法。我从Signature
对象获得了证书,并像这样检查它:
var x509data = signedXml.Signature.KeyInfo.OfType<KeyInfoX509Data>().First();
var verified = false;
if(x509data != null)
{
var cert = x509data.Certificates[0] as X509Certificate2;
verified = cert != null && signedXml.CheckSignature(cert, false);
}
return verified;
关于c# - 如何针对机器存储验证SignedXml中的证书,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6663733/