Beispiel #1
0
        public void LoadXml(XmlElement value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);

            nsm.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl);

            XmlNode cipherValueNode     = value.SelectSingleNode("enc:CipherValue", nsm);
            XmlNode cipherReferenceNode = value.SelectSingleNode("enc:CipherReference", nsm);

            if (cipherValueNode != null)
            {
                if (cipherReferenceNode != null)
                {
                    throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
                }
                m_cipherValue = Convert.FromBase64String(Utils.DiscardWhiteSpaces(cipherValueNode.InnerText));
            }
            else if (cipherReferenceNode != null)
            {
                m_cipherReference = new CipherReference();
                m_cipherReference.LoadXml((XmlElement)cipherReferenceNode);
            }
            else
            {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
            }

            // Save away the cached value
            m_cachedXml = value;
        }
Beispiel #2
0
        public void LoadXml(XmlElement value)
        {
            CipherReference = null;
            CipherValue     = null;

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if ((value.LocalName != XmlEncryption.ElementNames.CipherData) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl))
            {
                throw new CryptographicException("Malformed Cipher Data element.");
            }
            else
            {
                foreach (XmlNode n in value.ChildNodes)
                {
                    if (n is XmlWhitespace)
                    {
                        continue;
                    }

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

                    case XmlEncryption.ElementNames.CipherValue:
                        CipherValue = Convert.FromBase64String(n.InnerText);
                        break;
                    }
                }

                if (CipherReference == null && CipherValue == null)
                {
                    throw new CryptographicException("A Cipher Data element should have either a CipherValue or a CipherReference element.");
                }
            }
        }
Beispiel #3
0
        internal XmlElement GetXml(XmlDocument document)
        {
            // Create the CipherData element
            XmlElement cipherDataElement = (XmlElement)document.CreateElement("CipherData", EncryptedXml.XmlEncNamespaceUrl);

            if (CipherValue != null)
            {
                XmlElement cipherValueElement = document.CreateElement("CipherValue", EncryptedXml.XmlEncNamespaceUrl);
                cipherValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(CipherValue)));
                cipherDataElement.AppendChild(cipherValueElement);
            }
            else
            {
                // No CipherValue specified, see if there is a CipherReference
                if (CipherReference == null)
                {
                    throw new CryptographicException(SR.Cryptography_Xml_CipherValueElementRequired);
                }
                cipherDataElement.AppendChild(CipherReference.GetXml(document));
            }
            return(cipherDataElement);
        }
Beispiel #4
0
 public CipherData(CipherReference cipherReference)
 {
     CipherReference = cipherReference;
 }
Beispiel #5
0
        public void LoadXml (XmlElement value) {
            if (value == null)
                throw new ArgumentNullException("value");

            XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);
            nsm.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl);

            XmlNode cipherValueNode = value.SelectSingleNode("enc:CipherValue", nsm);
            XmlNode cipherReferenceNode = value.SelectSingleNode("enc:CipherReference", nsm);
            if (cipherValueNode != null) {
                if (cipherReferenceNode != null) 
                    throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
                m_cipherValue = Convert.FromBase64String(Utils.DiscardWhiteSpaces(cipherValueNode.InnerText));
            } else if (cipherReferenceNode != null) {
                m_cipherReference = new CipherReference();
                m_cipherReference.LoadXml((XmlElement) cipherReferenceNode);
            } else {
                throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
            }

            // Save away the cached value
            m_cachedXml = value;
        }
Beispiel #6
0
 public CipherData (CipherReference cipherReference) {
     this.CipherReference = cipherReference;
 }
Beispiel #7
0
		public void LoadXml (XmlElement value)
		{
			CipherReference = null;
			CipherValue = null;

			if (value == null)
				throw new ArgumentNullException ("value");

			if ((value.LocalName != XmlEncryption.ElementNames.CipherData) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl)) 
				throw new CryptographicException ("Malformed Cipher Data element.");
			else {
				foreach (XmlNode n in value.ChildNodes) {
					if (n is XmlWhitespace)
						continue;

					switch (n.LocalName) {
					case XmlEncryption.ElementNames.CipherReference:
						cipherReference = new CipherReference ();
						cipherReference.LoadXml ((XmlElement) n);
						break;
					case XmlEncryption.ElementNames.CipherValue:
						CipherValue = Convert.FromBase64String (n.InnerText);
						break;
					}
				}

				if (CipherReference == null && CipherValue == null)
					throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
			}
		}