예제 #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(this.Id))
            {
                encryptedDataElement.SetAttribute("Id", this.Id);
            }
            if (!String.IsNullOrEmpty(this.Type))
            {
                encryptedDataElement.SetAttribute("Type", this.Type);
            }
            if (!String.IsNullOrEmpty(this.MimeType))
            {
                encryptedDataElement.SetAttribute("MimeType", this.MimeType);
            }
            if (!String.IsNullOrEmpty(this.Encoding))
            {
                encryptedDataElement.SetAttribute("Encoding", this.Encoding);
            }

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

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

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

            // EncryptionProperties
            if (this.EncryptionProperties.Count > 0)
            {
                XmlElement encryptionPropertiesElement = document.CreateElement("EncryptionProperties", EncryptedXml.XmlEncNamespaceUrl);
                for (int index = 0; index < this.EncryptionProperties.Count; index++)
                {
                    EncryptionProperty ep = this.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(this.Id))
            {
                encryptedKeyElement.SetAttribute("Id", this.Id);
            }
            if (!String.IsNullOrEmpty(this.Type))
            {
                encryptedKeyElement.SetAttribute("Type", this.Type);
            }
            if (!String.IsNullOrEmpty(this.MimeType))
            {
                encryptedKeyElement.SetAttribute("MimeType", this.MimeType);
            }
            if (!String.IsNullOrEmpty(this.Encoding))
            {
                encryptedKeyElement.SetAttribute("Encoding", this.Encoding);
            }
            if (!String.IsNullOrEmpty(this.Recipient))
            {
                encryptedKeyElement.SetAttribute("Recipient", this.Recipient);
            }

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

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

            // CipherData
            if (this.CipherData == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_MissingCipherData"));
            }
            encryptedKeyElement.AppendChild(this.CipherData.GetXml(document));

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

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

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

            return(encryptedKeyElement);
        }