예제 #1
0
        /// <summary>Loads XML data from an <see cref="T:System.Xml.XmlElement" /> into a <see cref="T:System.Security.Cryptography.Xml.CipherData" /> object.</summary>
        /// <param name="value">An <see cref="T:System.Xml.XmlElement" /> that represents the XML data to load.</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.Security.Cryptography.Xml.CipherData.CipherValue" /> property and the <see cref="P:System.Security.Cryptography.Xml.CipherData.CipherReference" /> property are <see langword="null" />.</exception>
        public 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#");
            XmlNode xmlNode1 = value.SelectSingleNode("enc:CipherValue", nsmgr);
            XmlNode xmlNode2 = value.SelectSingleNode("enc:CipherReference", nsmgr);

            if (xmlNode1 != null)
            {
                if (xmlNode2 != null)
                {
                    throw new CryptographicException("Cryptography_Xml_CipherValueElementRequired");
                }
                this.m_cipherValue = Convert.FromBase64String(Exml.DiscardWhiteSpaces(xmlNode1.InnerText));
            }
            else
            {
                if (xmlNode2 == null)
                {
                    throw new CryptographicException("Cryptography_Xml_CipherValueElementRequired");
                }
                this.m_cipherReference = new CipherReference();
                this.m_cipherReference.LoadXml((XmlElement)xmlNode2);
            }
            this.m_cachedXml = value;
        }
예제 #2
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.Xml.CipherData" /> class using a <see cref="T:System.Security.Cryptography.Xml.CipherReference" /> object.</summary>
 /// <param name="cipherReference">The <see cref="T:System.Security.Cryptography.Xml.CipherReference" /> object to use.</param>
 /// <exception cref="T:System.Security.Cryptography.CryptographicException">The <see cref="P:System.Security.Cryptography.Xml.CipherData.CipherValue" /> property has already been set.</exception>
 public CipherData(CipherReference cipherReference)
 {
     this.CipherReference = cipherReference;
 }