0
SignedXmlDoc.CheckSignature總是在.NET 4.0中返回false,你可以請幫我在此對驗證SAML簽名SignedXmlDoc CheckSignature方法返回false
CryptoConfig.AddAlgorithm(typeof(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
X509Certificate2 cert = new X509Certificate2();
string text = System.IO.File.ReadAllText(@"D:\TFS\KCWBB\Dev-2\Source\KC.WEM.ITGSMI.Web\File\sig.cert");
cert.Import(Encoding.UTF8.GetBytes(text));
XmlNodeList XMLSignatures = xnlDoc.GetElementsByTagName("Signature", "http://www.w3.org/2000/09/xmldsig#");
KeyInfo key = new KeyInfo();
KeyInfoX509Data data = new KeyInfoX509Data(cert);
key.AddClause(data);
// Checking If the Response or the Assertion has been signed once and only once.
if (XMLSignatures.Count == 0) return false;
var signedXmlDoc = new SignedXml(xnlDoc);
signedXmlDoc.LoadXml((XmlElement)XMLSignatures[0]);
if (cert == null)
{
return false;
}
return signedXmlDoc.CheckSignature(cert,true);