我在这里看了关于这个问题的其他帖子,但似乎没有一个能解决我的情况.
我一直在尝试验证上周的SAML断言,我有2个客户端已经发送给我SAML但我无法验证它.
主要过程是我们得到一个base64编码的断言,我解码它.使用PreserveWhitespace = true将其加载到XmlDocment中.
验证方法是
public static bool Verify(X509Certificate2 cert, XmlElement xmlElement, SignedXml signedXml)
{
bool flag;
try
{
KeyInfo keyInfo = new KeyInfo();
var clause = new KeyInfoX509Data(cert);
keyInfo.AddClause(clause);
XmlElement signatureElement = GetSignatureElement(xmlElement);
if (signatureElement == null)
{
string message = "The XML does not contain a signature.";
throw new SAMLSignatureException(message);
}
signedXml.LoadXml(signatureElement);
if (keyInfo != null)
{
signedXml.KeyInfo = keyInfo;
}
SetSigningKeyFromKeyInfo(signedXml);
flag = signedXml.CheckSignature(cert.PublicKey.Key);
}
catch (Exception exception)
{
throw new SAMLSignatureException("Failed to verify the XML …Run Code Online (Sandbox Code Playgroud)