2 // CipherReference.cs - CipherReference implementation for XML Encryption
3 // http://www.w3.org/2001/04/xmlenc#sec-CipherReference
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Tim Coleman, 2004
14 namespace System.Security.Cryptography.Xml {
15 public sealed class CipherReference : EncryptedReference {
19 public CipherReference ()
24 public CipherReference (string uri)
29 public CipherReference (string uri, TransformChain tc)
34 #endregion // Constructors
38 public override XmlElement GetXml ()
40 return GetXml (new XmlDocument ());
43 internal override XmlElement GetXml (XmlDocument document)
45 XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.CipherReference, EncryptedXml.XmlEncNamespaceUrl);
47 xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
49 if (TransformChain != null && TransformChain.Count > 0) {
50 XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, EncryptedXml.XmlEncNamespaceUrl);
51 foreach (Transform t in TransformChain)
52 xtr.AppendChild (document.ImportNode (t.GetXml (), true));
53 xel.AppendChild (xtr);
59 public override void LoadXml (XmlElement value)
62 throw new ArgumentNullException ("value");
63 if ((value.LocalName != XmlEncryption.ElementNames.CipherReference) || (value.NamespaceURI != EncryptedXml.XmlEncNamespaceUrl))
64 throw new CryptographicException ("Malformed CipherReference element.");
67 TransformChain = new TransformChain ();
69 foreach (XmlNode n in value.ChildNodes) {
70 if (n is XmlWhitespace)
73 switch (n.LocalName) {
74 case XmlEncryption.ElementNames.Transforms:
75 foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) {
77 switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) {
78 case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform:
79 t = new XmlDsigBase64Transform ();
81 case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform:
82 t = new XmlDsigC14NTransform ();
84 case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform:
85 t = new XmlDsigC14NWithCommentsTransform ();
87 case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform:
88 t = new XmlDsigEnvelopedSignatureTransform ();
90 case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform:
91 t = new XmlDsigXPathTransform ();
93 case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform:
94 t = new XmlDsigXsltTransform ();
100 t.LoadInnerXml (((XmlElement) xn).ChildNodes);
101 TransformChain.Add (t);
107 if (value.HasAttribute (XmlEncryption.AttributeNames.URI))
108 Uri = value.Attributes [XmlEncryption.AttributeNames.URI].Value;
112 #endregion // Methods