• <i id='94qIQ'><tr id='94qIQ'><dt id='94qIQ'><q id='94qIQ'><span id='94qIQ'><b id='94qIQ'><form id='94qIQ'><ins id='94qIQ'></ins><ul id='94qIQ'></ul><sub id='94qIQ'></sub></form><legend id='94qIQ'></legend><bdo id='94qIQ'><pre id='94qIQ'><center id='94qIQ'></center></pre></bdo></b><th id='94qIQ'></th></span></q></dt></tr></i><div id='94qIQ'><tfoot id='94qIQ'></tfoot><dl id='94qIQ'><fieldset id='94qIQ'></fieldset></dl></div>
    1. <tfoot id='94qIQ'></tfoot>
      • <bdo id='94qIQ'></bdo><ul id='94qIQ'></ul>
      <legend id='94qIQ'><style id='94qIQ'><dir id='94qIQ'><q id='94qIQ'></q></dir></style></legend>

      1. <small id='94qIQ'></small><noframes id='94qIQ'>

        添加基于带有 SignedXml 类的 Id 属性的引用时出现

        时间:2023-06-02

          • <bdo id='B4QJS'></bdo><ul id='B4QJS'></ul>

              <small id='B4QJS'></small><noframes id='B4QJS'>

                <tbody id='B4QJS'></tbody>
                <tfoot id='B4QJS'></tfoot>
              • <legend id='B4QJS'><style id='B4QJS'><dir id='B4QJS'><q id='B4QJS'></q></dir></style></legend>
                <i id='B4QJS'><tr id='B4QJS'><dt id='B4QJS'><q id='B4QJS'><span id='B4QJS'><b id='B4QJS'><form id='B4QJS'><ins id='B4QJS'></ins><ul id='B4QJS'></ul><sub id='B4QJS'></sub></form><legend id='B4QJS'></legend><bdo id='B4QJS'><pre id='B4QJS'><center id='B4QJS'></center></pre></bdo></b><th id='B4QJS'></th></span></q></dt></tr></i><div id='B4QJS'><tfoot id='B4QJS'></tfoot><dl id='B4QJS'><fieldset id='B4QJS'></fieldset></dl></div>

                  本文介绍了添加基于带有 SignedXml 类的 Id 属性的引用时出现“格式错误的引用元素"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  当有命名空间前缀时,无法通过 Id 属性对元素进行签名:

                  Unable to sign element by Id attribute when there's a namespace prefix:

                  void Main()
                  {
                      var doc = new XmlDocument();
                      doc.LoadXml("<root xmlns:u="myuri"><test u:Id="_0">Zebra</test></root>");
                  
                      SignedXml signedXml = new SignedXml(doc);
                      signedXml.SigningKey = new RSACryptoServiceProvider();
                  
                      Reference reference = new Reference("#_0");
                      signedXml.AddReference(reference);
                  
                      signedXml.ComputeSignature();
                  }
                  

                  ComputeSignature() 将在此处失败并出现格式错误的参考元素",该怎么做?

                  ComputeSignature() will fail here with 'Malformed Reference Element' how should this be done?

                  推荐答案

                  我们使用的方法是继承 System.Security.Cryptography.Xml.SignedXml 类...

                  The approach we used was to subclass System.Security.Cryptography.Xml.SignedXml class...

                  public class SignedXmlWithId : SignedXml
                  {
                      public SignedXmlWithId(XmlDocument xml) : base(xml)
                      {
                      }
                  
                      public SignedXmlWithId(XmlElement xmlElement) 
                          : base(xmlElement)
                      {       
                      }
                  
                      public override XmlElement GetIdElement(XmlDocument doc, string id)
                      {
                          // check to see if it's a standard ID reference
                          XmlElement idElem = base.GetIdElement(doc, id);
                  
                          if (idElem == null)
                          {
                              XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
                              nsManager.AddNamespace("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
                  
                              idElem = doc.SelectSingleNode("//*[@wsu:Id="" + id + ""]", nsManager) as XmlElement;
                          }
                  
                          return idElem;
                      }
                  }
                  

                  这篇关于添加基于带有 SignedXml 类的 Id 属性的引用时出现“格式错误的引用元素"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么我需要使用 Rfc2898DeriveBytes 类(在 .NET 中)而 下一篇:使用 c# 计算 HMACSHA256 以匹配支付提供商示例

                  相关文章

                  最新文章

                1. <legend id='U1FzZ'><style id='U1FzZ'><dir id='U1FzZ'><q id='U1FzZ'></q></dir></style></legend>

                  <small id='U1FzZ'></small><noframes id='U1FzZ'>

                    <bdo id='U1FzZ'></bdo><ul id='U1FzZ'></ul>
                    <i id='U1FzZ'><tr id='U1FzZ'><dt id='U1FzZ'><q id='U1FzZ'><span id='U1FzZ'><b id='U1FzZ'><form id='U1FzZ'><ins id='U1FzZ'></ins><ul id='U1FzZ'></ul><sub id='U1FzZ'></sub></form><legend id='U1FzZ'></legend><bdo id='U1FzZ'><pre id='U1FzZ'><center id='U1FzZ'></center></pre></bdo></b><th id='U1FzZ'></th></span></q></dt></tr></i><div id='U1FzZ'><tfoot id='U1FzZ'></tfoot><dl id='U1FzZ'><fieldset id='U1FzZ'></fieldset></dl></div>

                      <tfoot id='U1FzZ'></tfoot>