小编Jon*_* S.的帖子

SignedXml checksignature返回false

我在这里看了关于这个问题的其他帖子,但似乎没有一个能解决我的情况.

我一直在尝试验证上周的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)

.net c# xml-signature

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

xml-signature ×1