Пример #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 System.Security.Cryptography.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)
        {
            XmlElement encryptedKeyElement = document.CreateElement("EncryptedKey", XmlNameSpace.Url[NS.XmlEncNamespaceUrl]);

            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);
            }

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

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

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

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

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

            if (CarriedKeyName != null)
            {
                XmlElement carriedKeyNameElement = document.CreateElement("CarriedKeyName", XmlNameSpace.Url[NS.XmlEncNamespaceUrl]);
                XmlText    carriedKeyNameText    = document.CreateTextNode(CarriedKeyName);
                carriedKeyNameElement.AppendChild(carriedKeyNameText);
                encryptedKeyElement.AppendChild(carriedKeyNameElement);
            }

            return(encryptedKeyElement);
        }