コード例 #1
0
        public override void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if ((value.LocalName != XmlEncryption.ElementNames.EncryptedData) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl))
            {
                throw new CryptographicException("Malformed EncryptedData element.");
            }
            else
            {
                EncryptionMethod = null;
                EncryptionMethod = null;
                EncryptionProperties.Clear();
                Id       = null;
                Type     = null;
                MimeType = null;
                Encoding = null;

                foreach (XmlNode n in value.ChildNodes)
                {
                    if (n is XmlWhitespace)
                    {
                        continue;
                    }

                    switch (n.LocalName)
                    {
                    case XmlEncryption.ElementNames.EncryptionMethod:
                        EncryptionMethod = new EncryptionMethod();
                        EncryptionMethod.LoadXml((XmlElement)n);
                        break;

                    case XmlSignature.ElementNames.KeyInfo:
                        KeyInfo = new KeyInfo();
                        KeyInfo.LoadXml((XmlElement)n);
                        break;

                    case XmlEncryption.ElementNames.CipherData:
                        CipherData = new CipherData();
                        CipherData.LoadXml((XmlElement)n);
                        break;

                    case XmlEncryption.ElementNames.EncryptionProperties:
                        foreach (XmlElement element in ((XmlElement)n).GetElementsByTagName(XmlEncryption.ElementNames.EncryptionProperty, EncryptedXml.XmlEncNamespaceUrl))
                        {
                            EncryptionProperties.Add(new EncryptionProperty(element));
                        }
                        break;
                    }
                }

                if (value.HasAttribute(XmlEncryption.AttributeNames.Id))
                {
                    Id = value.Attributes [XmlEncryption.AttributeNames.Id].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.Type))
                {
                    Type = value.Attributes [XmlEncryption.AttributeNames.Type].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.MimeType))
                {
                    MimeType = value.Attributes [XmlEncryption.AttributeNames.MimeType].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.Encoding))
                {
                    Encoding = value.Attributes [XmlEncryption.AttributeNames.Encoding].Value;
                }
            }
        }
コード例 #2
0
        public override void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if ((value.LocalName != XmlEncryption.ElementNames.EncryptedKey) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl))
            {
                throw new CryptographicException("Malformed EncryptedKey element.");
            }
            else
            {
                EncryptionMethod = null;
                EncryptionMethod = null;
                EncryptionProperties.Clear();
                ReferenceList.Clear();
                CarriedKeyName = null;
                Id             = null;
                Type           = null;
                MimeType       = null;
                Encoding       = null;
                Recipient      = null;

                foreach (XmlNode n in value.ChildNodes)
                {
                    if (n is XmlWhitespace)
                    {
                        continue;
                    }

                    switch (n.LocalName)
                    {
                    case XmlEncryption.ElementNames.EncryptionMethod:
                        EncryptionMethod = new EncryptionMethod();
                        EncryptionMethod.LoadXml((XmlElement)n);
                        break;

                    case XmlSignature.ElementNames.KeyInfo:
                        KeyInfo = new KeyInfo();
                        KeyInfo.LoadXml((XmlElement)n);
                        break;

                    case XmlEncryption.ElementNames.CipherData:
                        CipherData = new CipherData();
                        CipherData.LoadXml((XmlElement)n);
                        break;

                    case XmlEncryption.ElementNames.EncryptionProperties:
                        foreach (XmlElement element in ((XmlElement)n).GetElementsByTagName(XmlEncryption.ElementNames.EncryptionProperty, EncryptedXml.XmlEncNamespaceUrl))
                        {
                            EncryptionProperties.Add(new EncryptionProperty(element));
                        }
                        break;

                    case XmlEncryption.ElementNames.ReferenceList:
                        foreach (XmlNode r in ((XmlElement)n).ChildNodes)
                        {
                            if (r is XmlWhitespace)
                            {
                                continue;
                            }

                            switch (r.LocalName)
                            {
                            case XmlEncryption.ElementNames.DataReference:
                                DataReference dr = new DataReference();
                                dr.LoadXml((XmlElement)r);
                                AddReference(dr);
                                break;

                            case XmlEncryption.ElementNames.KeyReference:
                                KeyReference kr = new KeyReference();
                                kr.LoadXml((XmlElement)r);
                                AddReference(kr);
                                break;
                            }
                        }
                        break;

                    case XmlEncryption.ElementNames.CarriedKeyName:
                        CarriedKeyName = ((XmlElement)n).InnerText;
                        break;
                    }
                }

                if (value.HasAttribute(XmlEncryption.AttributeNames.Id))
                {
                    Id = value.Attributes [XmlEncryption.AttributeNames.Id].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.Type))
                {
                    Type = value.Attributes [XmlEncryption.AttributeNames.Type].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.MimeType))
                {
                    MimeType = value.Attributes [XmlEncryption.AttributeNames.MimeType].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.Encoding))
                {
                    Encoding = value.Attributes [XmlEncryption.AttributeNames.Encoding].Value;
                }
                if (value.HasAttribute(XmlEncryption.AttributeNames.Recipient))
                {
                    Encoding = value.Attributes [XmlEncryption.AttributeNames.Recipient].Value;
                }
            }
        }