/// <summary>Loads XML information into the <see langword="<CipherReference>" /> element in XML encryption.</summary> /// <param name="value">An <see cref="T:System.Xml.XmlElement" /> object that represents an XML element to use as the reference.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> provided is <see langword="null" />.</exception> public override void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } ReferenceType = value.LocalName; string attribute = Exml.GetAttribute(value, "URI", "http://www.w3.org/2001/04/xmlenc#"); if (attribute == null) { throw new CryptographicException("Cryptography_Xml_UriRequired"); } Uri = attribute; XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("enc", "http://www.w3.org/2001/04/xmlenc#"); XmlNode xmlNode = value.SelectSingleNode("enc:Transforms", nsmgr); if (xmlNode != null) { TransformChain.LoadXml(xmlNode as XmlElement); } m_cachedXml = value; }
internal void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); XmlNodeList xmlNodeList = value.SelectNodes("ds:Transform", nsmgr); if (xmlNodeList.Count == 0) { throw new CryptographicException("Cryptography_Xml_InvalidElement: Transforms"); } this.m_transforms.Clear(); for (int index = 0; index < xmlNodeList.Count; ++index) { XmlElement element = (XmlElement)xmlNodeList.Item(index); Transform fromName = Exml.CreateFromName <Transform>(Exml.GetAttribute(element, "Algorithm", "http://www.w3.org/2000/09/xmldsig#")); if (fromName == null) { throw new CryptographicException("Cryptography_Xml_UnknownTransform"); } fromName.LoadInnerXml(element.ChildNodes); this.m_transforms.Add((object)fromName); } }
/// <summary>Parses the specified <see cref="T:System.Xml.XmlNodeList" /> object as transform-specific content of a <see langword="<Transform>" /> element and configures the internal state of the current <see cref="T:System.Security.Cryptography.Xml.XmlDsigExcC14NTransform" /> object to match the <see langword="<Transform>" /> element.</summary> /// <param name="nodeList">An <see cref="T:System.Xml.XmlNodeList" /> object that specifies transform-specific content for the current <see cref="T:System.Security.Cryptography.Xml.XmlDsigExcC14NTransform" /> object.</param> public override void LoadInnerXml(XmlNodeList nodeList) { if (nodeList == null) { return; } foreach (XmlNode node in nodeList) { XmlElement element = node as XmlElement; if (element != null) { if (element.LocalName.Equals("InclusiveNamespaces") && element.NamespaceURI.Equals("http://www.w3.org/2001/10/xml-exc-c14n#") && Exml.HasAttribute(element, "PrefixList", "http://www.w3.org/2000/09/xmldsig#")) { if (!Exml.VerifyAttributes(element, "PrefixList")) { throw new CryptographicException("Cryptography_Xml_UnknownTransform"); } this.InclusiveNamespacesPrefixList = Exml.GetAttribute(element, "PrefixList", "http://www.w3.org/2000/09/xmldsig#"); break; } } } }
/// <summary>Parses the input <see cref="T:System.Xml.XmlElement" /> object and configures the internal state of the <see cref="T:System.Security.Cryptography.Xml.KeyInfoRetrievalMethod" /> object to match.</summary> /// <param name="value">The XML element that specifies the state of the <see cref="T:System.Security.Cryptography.Xml.KeyInfoRetrievalMethod" /> object. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />. </exception> public override void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } this.m_uri = Exml.GetAttribute(value, "URI", "http://www.w3.org/2000/09/xmldsig#"); this.m_type = Exml.GetAttribute(value, "Type", "http://www.w3.org/2000/09/xmldsig#"); }
/// <summary>Parses the input <see cref="T:System.Xml.XmlElement" /> and configures the internal state of the <see cref="T:System.Security.Cryptography.Xml.EncryptionProperty" /> object to match.</summary> /// <param name="value">An <see cref="T:System.Xml.XmlElement" /> object to parse.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />.</exception> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <see cref="P:System.Xml.XmlElement.LocalName" /> property of the <paramref name="value" /> parameter is not "EncryptionProperty". -or-The <see cref="P:System.Xml.XmlElement.NamespaceURI" /> property of the <paramref name="value" /> parameter is not "http://www.w3.org/2001/04/xmlenc#".</exception> public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } if (value.LocalName != nameof(EncryptionProperty) || value.NamespaceURI != "http://www.w3.org/2001/04/xmlenc#") { throw new CryptographicException("Cryptography_Xml_InvalidEncryptionProperty"); } m_cachedXml = value; Id = Exml.GetAttribute(value, "Id", "http://www.w3.org/2001/04/xmlenc#"); Target = Exml.GetAttribute(value, "Target", "http://www.w3.org/2001/04/xmlenc#"); m_elemProp = value; }
/// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.DataObject" /> state from an XML element.</summary> /// <param name="value">The XML element to load the <see cref="T:System.Security.Cryptography.Xml.DataObject" /> state from. </param> /// <exception cref="T:System.ArgumentNullException">The value from the XML element is <see langword="null" />.</exception> public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } m_id = Exml.GetAttribute(value, "Id", "http://www.w3.org/2000/09/xmldsig#"); m_mimeType = Exml.GetAttribute(value, "MimeType", "http://www.w3.org/2000/09/xmldsig#"); m_encoding = Exml.GetAttribute(value, "Encoding", "http://www.w3.org/2000/09/xmldsig#"); foreach (XmlNode childNode in value.ChildNodes) { m_elData.Add((object)childNode); } m_cachedXml = value; }
/// <summary>Loads an XML element into an <see cref="T:System.Security.Cryptography.Xml.EncryptedReference" /> object.</summary> /// <param name="value">An <see cref="T:System.Xml.XmlElement" /> object that represents an XML element.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />.</exception> public virtual void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } this.ReferenceType = value.LocalName; this.Uri = Exml.GetAttribute(value, "URI", "http://www.w3.org/2001/04/xmlenc#"); XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); XmlNode xmlNode = value.SelectSingleNode("ds:Transforms", nsmgr); if (xmlNode != null) { this.TransformChain.LoadXml(xmlNode as XmlElement); } this.m_cachedXml = value; }
/// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.KeyInfo" /> state from an XML element.</summary> /// <param name="value">The XML element from which to load the <see cref="T:System.Security.Cryptography.Xml.KeyInfo" /> state. </param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="value" /> parameter is <see langword="null" />. </exception> public void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } XmlElement element1 = value; this.m_id = Exml.GetAttribute(element1, "Id", "http://www.w3.org/2000/09/xmldsig#"); if (!Exml.VerifyAttributes(element1, "Id")) { throw new CryptographicException("Invalid XML element: KeyInfo"); } for (XmlNode xmlNode = element1.FirstChild; xmlNode != null; xmlNode = xmlNode.NextSibling) { XmlElement element2 = xmlNode as XmlElement; if (element2 != null) { string key = element2.NamespaceURI + " " + element2.LocalName; if (key == "http://www.w3.org/2000/09/xmldsig# KeyValue") { if (!Exml.VerifyAttributes(element2, (string[])null)) { throw new CryptographicException("Invalid XML element: KeyInfo/KeyValue"); } foreach (XmlNode childNode in element2.ChildNodes) { XmlElement xmlElement = childNode as XmlElement; if (xmlElement != null) { key = key + "/" + xmlElement.LocalName; break; } } } KeyInfoClause clause = Exml.CreateFromName <KeyInfoClause>(key) ?? (KeyInfoClause) new KeyInfoNode(); clause.LoadXml(element2); this.AddClause(clause); } } }
/// <summary>Loads the specified XML information into the <see langword="<EncryptedKey>" /> element in XML encryption.</summary> /// <param name="value">An <see cref="T:System.Xml.XmlElement" /> representing an XML element to use for the <see langword="<EncryptedKey>" /> element.</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 <see cref="T:System.Security.Cryptography.Xml.CipherData" /> element.</exception> public override void LoadXml(XmlElement value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } XmlNamespaceManager nsmgr = new XmlNamespaceManager(value.OwnerDocument.NameTable); nsmgr.AddNamespace("enc", "http://www.w3.org/2001/04/xmlenc#"); nsmgr.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#"); Id = Exml.GetAttribute(value, "Id", "http://www.w3.org/2001/04/xmlenc#"); Type = Exml.GetAttribute(value, "Type", "http://www.w3.org/2001/04/xmlenc#"); MimeType = Exml.GetAttribute(value, "MimeType", "http://www.w3.org/2001/04/xmlenc#"); Encoding = Exml.GetAttribute(value, "Encoding", "http://www.w3.org/2001/04/xmlenc#"); Recipient = Exml.GetAttribute(value, "Recipient", "http://www.w3.org/2001/04/xmlenc#"); XmlNode xmlNode1 = value.SelectSingleNode("enc:EncryptionMethod", nsmgr); EncryptionMethod = new EncryptionMethod(); if (xmlNode1 != null) { EncryptionMethod.LoadXml(xmlNode1 as XmlElement); } KeyInfo = new KeyInfo(); XmlNode xmlNode2 = value.SelectSingleNode("ds:KeyInfo", nsmgr); if (xmlNode2 != null) { KeyInfo.LoadXml(xmlNode2 as XmlElement); } XmlNode xmlNode3 = value.SelectSingleNode("enc:CipherData", nsmgr); if (xmlNode3 == null) { throw new CryptographicException("Cryptography_Xml_MissingCipherData"); } CipherData = new CipherData(); CipherData.LoadXml(xmlNode3 as XmlElement); XmlNode xmlNode4 = value.SelectSingleNode("enc:EncryptionProperties", nsmgr); if (xmlNode4 != null) { XmlNodeList xmlNodeList = xmlNode4.SelectNodes("enc:EncryptionProperty", nsmgr); if (xmlNodeList != null) { foreach (XmlNode xmlNode5 in xmlNodeList) { EncryptionProperty encryptionProperty = new EncryptionProperty(); encryptionProperty.LoadXml(xmlNode5 as XmlElement); EncryptionProperties.Add(encryptionProperty); } } } XmlNode xmlNode6 = value.SelectSingleNode("enc:CarriedKeyName", nsmgr); if (xmlNode6 != null) { CarriedKeyName = xmlNode6.InnerText; } XmlNode xmlNode7 = value.SelectSingleNode("enc:ReferenceList", nsmgr); if (xmlNode7 != null) { XmlNodeList xmlNodeList1 = xmlNode7.SelectNodes("enc:DataReference", nsmgr); if (xmlNodeList1 != null) { foreach (XmlNode xmlNode5 in xmlNodeList1) { DataReference dataReference = new DataReference(); dataReference.LoadXml(xmlNode5 as XmlElement); ReferenceList.Add((object)dataReference); } } XmlNodeList xmlNodeList2 = xmlNode7.SelectNodes("enc:KeyReference", nsmgr); if (xmlNodeList2 != null) { foreach (XmlNode xmlNode5 in xmlNodeList2) { KeyReference keyReference = new KeyReference(); keyReference.LoadXml(xmlNode5 as XmlElement); ReferenceList.Add((object)keyReference); } } } m_cachedXml = value; }
/// <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)"); } }