コード例 #1
0
ファイル: EncryptedData.cs プロジェクト: pedrobsaila/runtime
        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)
        {
            if (CipherData == null)
            {
                throw new CryptographicException("Cipher data is not specified.");
            }

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

            if (EncryptionMethod != null)
            {
                xel.AppendChild(EncryptionMethod.GetXml(document));
            }
            if (KeyInfo != null)
            {
                xel.AppendChild(document.ImportNode(KeyInfo.GetXml(), true));
            }
            if (CipherData != null)
            {
                xel.AppendChild(CipherData.GetXml(document));
            }

            if (EncryptionProperties.Count > 0)
            {
                XmlElement xep = document.CreateElement(XmlEncryption.ElementNames.EncryptionProperties, EncryptedXml.XmlEncNamespaceUrl);
                foreach (EncryptionProperty p in EncryptionProperties)
                {
                    xep.AppendChild(p.GetXml(document));
                }
                xel.AppendChild(xep);
            }

            if (Id != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Id, Id);
            }
            if (Type != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Type, Type);
            }
            if (MimeType != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.MimeType, MimeType);
            }
            if (Encoding != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Encoding, Encoding);
            }
            return(xel);
        }
コード例 #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);
        }
コード例 #4
0
        internal XmlElement GetXml(XmlDocument document)
        {
            if (CipherData == null)
            {
                throw new CryptographicException("Cipher data is not specified.");
            }

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

            if (EncryptionMethod != null)
            {
                xel.AppendChild(EncryptionMethod.GetXml(document));
            }
            if (KeyInfo != null)
            {
                xel.AppendChild(document.ImportNode(KeyInfo.GetXml(), true));
            }
            if (CipherData != null)
            {
                xel.AppendChild(CipherData.GetXml(document));
            }

            if (EncryptionProperties.Count > 0)
            {
                XmlElement xep = document.CreateElement(XmlEncryption.ElementNames.EncryptionProperties, EncryptedXml.XmlEncNamespaceUrl);
                foreach (EncryptionProperty p in EncryptionProperties)
                {
                    xep.AppendChild(p.GetXml(document));
                }
                xel.AppendChild(xep);
            }

            if (ReferenceList.Count > 0)
            {
                XmlElement xrl = document.CreateElement(XmlEncryption.ElementNames.ReferenceList, EncryptedXml.XmlEncNamespaceUrl);
                foreach (EncryptedReference er in ReferenceList)
                {
                    xrl.AppendChild(er.GetXml(document));
                }
                xel.AppendChild(xrl);
            }

            if (CarriedKeyName != null)
            {
                XmlElement xck = document.CreateElement(XmlEncryption.ElementNames.CarriedKeyName, EncryptedXml.XmlEncNamespaceUrl);
                xck.InnerText = CarriedKeyName;
                xel.AppendChild(xck);
            }

            if (Id != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Id, Id);
            }
            if (Type != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Type, Type);
            }
            if (MimeType != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.MimeType, MimeType);
            }
            if (Encoding != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Encoding, Encoding);
            }
            if (Recipient != null)
            {
                xel.SetAttribute(XmlEncryption.AttributeNames.Recipient, Recipient);
            }
            return(xel);
        }