Beispiel #1
0
 /// <summary>Adds a <see cref="T:System.Security.Cryptography.Xml.DataObject" /> to the list of objects to be signed.</summary>
 /// <param name="dataObject">The <see cref="T:System.Security.Cryptography.Xml.DataObject" /> to be added to the list of objects to be signed. </param>
 public void AddObject(DataObject dataObject)
 {
     this.m_embeddedObjects.Add((object)dataObject);
 }
Beispiel #2
0
        /// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.Signature" /> state from an XML element.</summary>
        /// <param name="value">The XML element from which to load the <see cref="T:System.Security.Cryptography.Xml.Signature" /> state. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />. </exception>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <paramref name="value" /> parameter does not contain a valid <see cref="P:System.Security.Cryptography.Xml.Signature.SignatureValue" />.-or- The <paramref name="value" /> parameter does not contain a valid <see cref="P:System.Security.Cryptography.Xml.Signature.SignedInfo" />. </exception>
        public void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            XmlElement element1 = value;

            if (!element1.LocalName.Equals(nameof(Signature)))
            {
                throw new CryptographicException("Invalid element: Signature (1)");
            }
            this.m_id = Exml.GetAttribute(element1, "Id", "http://www.w3.org/2000/09/xmldsig#");
            if (!Exml.VerifyAttributes(element1, "Id"))
            {
                throw new CryptographicException("Invalid element: Signature (2)");
            }
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable);

            nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
            int         num1         = 0;
            XmlNodeList xmlNodeList1 = element1.SelectNodes("ds:SignedInfo", nsmgr);

            if (xmlNodeList1 == null || xmlNodeList1.Count == 0 || xmlNodeList1.Count > 1)
            {
                throw new CryptographicException("Invalid element: SignedInfo");
            }
            XmlElement xmlElement1 = xmlNodeList1[0] as XmlElement;
            int        num2        = num1 + xmlNodeList1.Count;

            this.SignedInfo = new SignedInfo();
            this.SignedInfo.LoadXml(xmlElement1);
            XmlNodeList xmlNodeList2 = element1.SelectNodes("ds:SignatureValue", nsmgr);

            if (xmlNodeList2 == null || xmlNodeList2.Count == 0 || xmlNodeList2.Count > 1)
            {
                throw new CryptographicException("Invalid element: SignatureValue (1)");
            }
            XmlElement element2 = xmlNodeList2[0] as XmlElement;
            int        num3     = num2 + xmlNodeList2.Count;

            this.m_signatureValue   = Convert.FromBase64String(Exml.DiscardWhiteSpaces(element2.InnerText, 0, element2.InnerText.Length));
            this.m_signatureValueId = Exml.GetAttribute(element2, "Id", "http://www.w3.org/2000/09/xmldsig#");
            if (!Exml.VerifyAttributes(element2, "Id"))
            {
                throw new CryptographicException("Invalid element: SignatureValue (2)");
            }
            XmlNodeList xmlNodeList3 = element1.SelectNodes("ds:KeyInfo", nsmgr);

            this.m_keyInfo = new KeyInfo();
            if (xmlNodeList3 != null)
            {
                if (xmlNodeList3.Count > 1)
                {
                    throw new CryptographicException("Invalid element: KeyInfo");
                }
                foreach (XmlNode xmlNode in xmlNodeList3)
                {
                    XmlElement xmlElement2 = xmlNode as XmlElement;
                    if (xmlElement2 != null)
                    {
                        this.m_keyInfo.LoadXml(xmlElement2);
                    }
                }
                num3 += xmlNodeList3.Count;
            }
            XmlNodeList xmlNodeList4 = element1.SelectNodes("ds:Object", nsmgr);

            this.m_embeddedObjects.Clear();
            if (xmlNodeList4 != null)
            {
                foreach (XmlNode xmlNode in xmlNodeList4)
                {
                    XmlElement xmlElement2 = xmlNode as XmlElement;
                    if (xmlElement2 != null)
                    {
                        DataObject dataObject = new DataObject();
                        dataObject.LoadXml(xmlElement2);
                        this.m_embeddedObjects.Add((object)dataObject);
                    }
                }
                num3 += xmlNodeList4.Count;
            }
            XmlNodeList xmlNodeList5 = element1.SelectNodes("//*[@Id]", nsmgr);

            if (xmlNodeList5 != null)
            {
                foreach (XmlNode xmlNode in xmlNodeList5)
                {
                    this.m_referencedItems.Add((object)xmlNode);
                }
            }
            if (element1.SelectNodes("*").Count != num3)
            {
                throw new CryptographicException("Invalid element: Signature (3)");
            }
        }