签名XML检查签名失败,哈希错误
我正在尝试检查DOT NET中的SAML签名的响应4.8 MVC项目,
我的代码是
_xmlDoc = new XmlDocument();
_xmlDoc.PreserveWhitespace = true;
_xmlDoc.XmlResolver = null;
_xmlDoc.LoadXml(xml);
XmlNodeList nodeList = _xmlDoc.SelectNodes("//ds:Signature", _xmlNameSpaceManager);
SignedXml signedXml = new SignedXml(_xmlDoc);
if (nodeList.Count == 0) return false;
signedXml.LoadXml((XmlElement)nodeList[0]);
X509Certificate2 serviceCertificate = null;
foreach (KeyInfoClause clause in signedXml.KeyInfo)
{
if (clause is KeyInfoX509Data)
{
if (((KeyInfoX509Data)clause).Certificates.Count > 0)
{
serviceCertificate = (X509Certificate2)((KeyInfoX509Data)clause).Certificates[0];
}
}
}
return signedXml.CheckSignature(serviceCertificate, true);
false作为签名验证,
因此我启用了日志,以下是错误,
[SignedXml#026c9e6f, VerifyReference] Reference Reference#000df9b5 hashed with
"http://www.w3.org/2001/04/xmlenc#sha256" (SHA256Managed) has hash value
348aa65d5b67edfae901cd4e2596065e75839a18c9a5d3a63d3fd85e48c232d8, expected hash value
869e1b0273833271a23349cd9bc7bddb597c2277c323abddead0cfe798ae3f63.
System.Security.Cryptography.Xml.SignedXml Information: 12 : [SignedXml#026c9e6f,
VerificationFailure] Verification failed checking references.
请建议建议
I am trying to check SAML Signed Response in Dot Net 4.8 MVC Project
My code is
_xmlDoc = new XmlDocument();
_xmlDoc.PreserveWhitespace = true;
_xmlDoc.XmlResolver = null;
_xmlDoc.LoadXml(xml);
XmlNodeList nodeList = _xmlDoc.SelectNodes("//ds:Signature", _xmlNameSpaceManager);
SignedXml signedXml = new SignedXml(_xmlDoc);
if (nodeList.Count == 0) return false;
signedXml.LoadXml((XmlElement)nodeList[0]);
X509Certificate2 serviceCertificate = null;
foreach (KeyInfoClause clause in signedXml.KeyInfo)
{
if (clause is KeyInfoX509Data)
{
if (((KeyInfoX509Data)clause).Certificates.Count > 0)
{
serviceCertificate = (X509Certificate2)((KeyInfoX509Data)clause).Certificates[0];
}
}
}
return signedXml.CheckSignature(serviceCertificate, true);
Its getting false as signature validation
So I enabled logs and below is the error
[SignedXml#026c9e6f, VerifyReference] Reference Reference#000df9b5 hashed with
"http://www.w3.org/2001/04/xmlenc#sha256" (SHA256Managed) has hash value
348aa65d5b67edfae901cd4e2596065e75839a18c9a5d3a63d3fd85e48c232d8, expected hash value
869e1b0273833271a23349cd9bc7bddb597c2277c323abddead0cfe798ae3f63.
System.Security.Cryptography.Xml.SignedXml Information: 12 : [SignedXml#026c9e6f,
VerificationFailure] Verification failed checking references.
Please suggest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论