Пример #1
0
        internal XmlElement GetXml(XmlDocument document)
        {
            // Create the EncryptedData element
            XmlElement encryptedDataElement = (XmlElement)document.CreateElement("EncryptedData", EncryptedXml.XmlEncNamespaceUrl);

            // Deal with attributes
            if (!string.IsNullOrEmpty(Id))
            {
                encryptedDataElement.SetAttribute("Id", Id);
            }
            if (!string.IsNullOrEmpty(Type))
            {
                encryptedDataElement.SetAttribute("Type", Type);
            }
            if (!string.IsNullOrEmpty(MimeType))
            {
                encryptedDataElement.SetAttribute("MimeType", MimeType);
            }
            if (!string.IsNullOrEmpty(Encoding))
            {
                encryptedDataElement.SetAttribute("Encoding", Encoding);
            }

            // EncryptionMethod
            if (EncryptionMethod != null)
            {
                encryptedDataElement.AppendChild(EncryptionMethod.GetXml(document));
            }

            // KeyInfo
            if (KeyInfo.Count > 0)
            {
                encryptedDataElement.AppendChild(KeyInfo.GetXml(document));
            }

            // CipherData is required.
            if (CipherData == null)
            {
                throw new CryptographicException(SR.Cryptography_Xml_MissingCipherData);
            }
            encryptedDataElement.AppendChild(CipherData.GetXml(document));

            // EncryptionProperties
            if (EncryptionProperties.Count > 0)
            {
                XmlElement encryptionPropertiesElement = document.CreateElement("EncryptionProperties", EncryptedXml.XmlEncNamespaceUrl);
                for (int index = 0; index < EncryptionProperties.Count; index++)
                {
                    EncryptionProperty ep = EncryptionProperties.Item(index);
                    encryptionPropertiesElement.AppendChild(ep.GetXml(document));
                }
                encryptedDataElement.AppendChild(encryptionPropertiesElement);
            }
            return(encryptedDataElement);
        }
Пример #2
0
        internal XmlElement GetXml(XmlDocument document)
        {
            // Create the EncryptedKey element
            XmlElement encryptedKeyElement = (XmlElement)document.CreateElement("EncryptedKey", EncryptedXml.XmlEncNamespaceUrl);

            // Deal with attributes
            if (!string.IsNullOrEmpty(Id))
            {
                encryptedKeyElement.SetAttribute("Id", Id);
            }
            if (!string.IsNullOrEmpty(Type))
            {
                encryptedKeyElement.SetAttribute("Type", Type);
            }
            if (!string.IsNullOrEmpty(MimeType))
            {
                encryptedKeyElement.SetAttribute("MimeType", MimeType);
            }
            if (!string.IsNullOrEmpty(Encoding))
            {
                encryptedKeyElement.SetAttribute("Encoding", Encoding);
            }
            if (!string.IsNullOrEmpty(Recipient))
            {
                encryptedKeyElement.SetAttribute("Recipient", Recipient);
            }

            // EncryptionMethod
            if (EncryptionMethod != null)
            {
                encryptedKeyElement.AppendChild(EncryptionMethod.GetXml(document));
            }

            // KeyInfo
            if (KeyInfo.Count > 0)
            {
                encryptedKeyElement.AppendChild(KeyInfo.GetXml(document));
            }

            // CipherData
            if (CipherData == null)
            {
                throw new CryptographicException(SR.Cryptography_Xml_MissingCipherData);
            }
            encryptedKeyElement.AppendChild(CipherData.GetXml(document));

            // EncryptionProperties
            if (EncryptionProperties.Count > 0)
            {
                XmlElement encryptionPropertiesElement = document.CreateElement("EncryptionProperties", EncryptedXml.XmlEncNamespaceUrl);
                for (int index = 0; index < EncryptionProperties.Count; index++)
                {
                    EncryptionProperty ep = EncryptionProperties.Item(index);
                    encryptionPropertiesElement.AppendChild(ep.GetXml(document));
                }
                encryptedKeyElement.AppendChild(encryptionPropertiesElement);
            }

            // ReferenceList
            if (ReferenceList.Count > 0)
            {
                XmlElement referenceListElement = document.CreateElement("ReferenceList", EncryptedXml.XmlEncNamespaceUrl);
                for (int index = 0; index < ReferenceList.Count; index++)
                {
                    referenceListElement.AppendChild(ReferenceList[index].GetXml(document));
                }
                encryptedKeyElement.AppendChild(referenceListElement);
            }

            // CarriedKeyName
            if (CarriedKeyName != null)
            {
                XmlElement carriedKeyNameElement = (XmlElement)document.CreateElement("CarriedKeyName", EncryptedXml.XmlEncNamespaceUrl);
                XmlText    carriedKeyNameText    = document.CreateTextNode(CarriedKeyName);
                carriedKeyNameElement.AppendChild(carriedKeyNameText);
                encryptedKeyElement.AppendChild(carriedKeyNameElement);
            }

            return(encryptedKeyElement);
        }