Пример #1
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 CryptographicException(SR.Cryptography_Xml_CipherValueElementRequired);
                }
                cipherDataElement.AppendChild(CipherReference.GetXml(document));
            }
            return(cipherDataElement);
        }
Пример #2
0
        internal XmlElement GetXml(XmlDocument document)
        {
            if (CipherReference == null && CipherValue == null)
            {
                throw new CryptographicException("A Cipher Data element should have either a CipherValue or a CipherReference element.");
            }

            XmlElement xel = document.CreateElement(XmlEncryption.ElementNames.CipherData, EncryptedXml.XmlEncNamespaceUrl);

            if (CipherReference != null)
            {
                xel.AppendChild(document.ImportNode(cipherReference.GetXml(), true));
            }

            if (CipherValue != null)
            {
                XmlElement   xcv    = document.CreateElement(XmlEncryption.ElementNames.CipherValue, EncryptedXml.XmlEncNamespaceUrl);
                StreamReader reader = new StreamReader(new CryptoStream(new MemoryStream(cipherValue), new ToBase64Transform(), CryptoStreamMode.Read));
                xcv.InnerText = reader.ReadToEnd();
                reader.Close();
                xel.AppendChild(xcv);
            }
            return(xel);
        }