示例#1
0
        public void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);

            nsm.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl);

            XmlNode cipherValueNode     = value.SelectSingleNode("enc:CipherValue", nsm);
            XmlNode cipherReferenceNode = value.SelectSingleNode("enc:CipherReference", nsm);

            if (cipherValueNode != null)
            {
                if (cipherReferenceNode != null)
                {
                    throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_CipherValueElementRequired);
                }
                _cipherValue = Convert.FromBase64String(Utils.DiscardWhiteSpaces(cipherValueNode.InnerText));
            }
            else if (cipherReferenceNode != null)
            {
                _cipherReference = new CipherReference();
                _cipherReference.LoadXml((XmlElement)cipherReferenceNode);
            }
            else
            {
                throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_CipherValueElementRequired);
            }

            // Save away the cached value
            _cachedXml = value;
        }
示例#2
0
        internal XmlElement GetXml(XmlDocument document)
        {
            XmlElement cipherDataElement = document.CreateElement("CipherData", XmlNameSpace.Url[NS.XmlEncNamespaceUrl]);

            if (CipherValue != null)
            {
                XmlElement cipherValueElement = document.CreateElement("CipherValue", XmlNameSpace.Url[NS.XmlEncNamespaceUrl]);
                cipherValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(CipherValue)));
                cipherDataElement.AppendChild(cipherValueElement);
            }
            else
            {
                if (CipherReference == null)
                {
                    throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_CipherValueElementRequired);
                }
                cipherDataElement.AppendChild(CipherReference.GetXml(document));
            }
            return(cipherDataElement);
        }
示例#3
0
        internal XmlElement GetXml(XmlDocument document)
        {
            // Create the CipherData element
            XmlElement cipherDataElement = (XmlElement)document.CreateElement("CipherData", EncryptedXml.XmlEncNamespaceUrl);

            if (CipherValue != null)
            {
                XmlElement cipherValueElement = document.CreateElement("CipherValue", EncryptedXml.XmlEncNamespaceUrl);
                cipherValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(CipherValue)));
                cipherDataElement.AppendChild(cipherValueElement);
            }
            else
            {
                // No CipherValue specified, see if there is a CipherReference
                if (CipherReference == null)
                {
                    throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_CipherValueElementRequired);
                }
                cipherDataElement.AppendChild(CipherReference.GetXml(document));
            }
            return(cipherDataElement);
        }
示例#4
0
 public CipherData(CipherReference cipherReference)
 {
     CipherReference = cipherReference;
 }