Exemplo n.º 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);
        }
Exemplo n.º 2
0
        internal XmlElement GetXml(XmlDocument document)
        {
            XmlElement element = document.CreateElement("EncryptedData", "http://www.w3.org/2001/04/xmlenc#");

            if (!string.IsNullOrEmpty(this.Id))
            {
                element.SetAttribute("Id", this.Id);
            }
            if (!string.IsNullOrEmpty(this.Type))
            {
                element.SetAttribute("Type", this.Type);
            }
            if (!string.IsNullOrEmpty(this.MimeType))
            {
                element.SetAttribute("MimeType", this.MimeType);
            }
            if (!string.IsNullOrEmpty(this.Encoding))
            {
                element.SetAttribute("Encoding", this.Encoding);
            }
            if (this.EncryptionMethod != null)
            {
                element.AppendChild(this.EncryptionMethod.GetXml(document));
            }
            if (base.KeyInfo.Count > 0)
            {
                element.AppendChild(base.KeyInfo.GetXml(document));
            }
            if (this.CipherData == null)
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_MissingCipherData"));
            }
            element.AppendChild(this.CipherData.GetXml(document));
            if (this.EncryptionProperties.Count > 0)
            {
                XmlElement newChild = document.CreateElement("EncryptionProperties", "http://www.w3.org/2001/04/xmlenc#");
                for (int i = 0; i < this.EncryptionProperties.Count; i++)
                {
                    EncryptionProperty property = this.EncryptionProperties.Item(i);
                    newChild.AppendChild(property.GetXml(document));
                }
                element.AppendChild(newChild);
            }
            return(element);
        }
Exemplo n.º 3
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);
        }