+2004-02-07 Tim Coleman <tim@timcoleman.com>
+ * CipherData.cs CipherReference.cs EncryptedData.cs
+ * EncryptedReference.cs EncryptedType.cs EncryptionMethod.cs
+ * EncryptionProperties.cs EncryptionProperty.cs XmlEncryption.cs:
+ New classes added for Xml Encryption in 1.2
+ * KeyInfoRetrievalMethod.cs:
+ Added Type attribute for 1.2
+ * XmlSignature.cs:
+ Added string constants for algorithm namespaces
+
2004-01-11 Sebastien Pouliot <spouliot@videotron.ca>
* SignedXml.cs: Fixed class signature (for 1.1+) by adding public to
--- /dev/null
+//
+// CipherData.cs - CipherData implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-CipherData
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Security.Cryptography;
+using System.IO;
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public sealed class CipherData {
+
+ #region Fields
+
+ byte[] cipherValue;
+ CipherReference cipherReference;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ public CipherData ()
+ {
+ }
+
+ public CipherData (byte[] cipherValue)
+ {
+ CipherValue = cipherValue;
+ }
+
+ public CipherData (CipherReference cipherReference)
+ {
+ CipherReference = cipherReference;
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public CipherReference CipherReference {
+ get { return cipherReference; }
+ set {
+ if (CipherValue != null)
+ throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+ cipherReference = value;
+ }
+ }
+
+ public byte[] CipherValue {
+ get { return cipherValue; }
+ set {
+ if (CipherReference != null)
+ throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+ cipherValue = value;
+ }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public XmlElement GetXml ()
+ {
+ return GetXml (new XmlDocument ());
+ }
+
+ internal XmlElement GetXml (XmlDocument document)
+ {
+ if (CipherReference == null && CipherValue == null)
+ throw new CryptographicException ("A Cipher Data element should have either a CipherValue or a CipherReference element.");
+
+ XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.CipherData, XmlEncryption.NamespaceURI);
+ if (CipherReference != null)
+ xel.AppendChild (document.ImportNode (cipherReference.GetXml (), true));
+
+ if (CipherValue != null) {
+ XmlElement xcv = document.CreateElement (XmlEncryption.ElementNames.CipherValue, XmlEncryption.NamespaceURI);
+ StreamReader reader = new StreamReader (new CryptoStream (new MemoryStream (cipherValue), new ToBase64Transform (), CryptoStreamMode.Read));
+ xcv.InnerText = reader.ReadToEnd ();
+ reader.Close ();
+ xel.AppendChild (xcv);
+ }
+ return xel;
+ }
+
+ public void LoadXml (XmlElement value)
+ {
+ CipherReference = null;
+ CipherValue = null;
+
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ if ((value.LocalName != XmlEncryption.ElementNames.CipherData) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+ 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.");
+ }
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// CipherReference.cs - CipherReference implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-CipherReference
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public sealed class CipherReference : EncryptedReference {
+
+ #region Constructors
+
+ public CipherReference ()
+ : base ()
+ {
+ }
+
+ public CipherReference (string uri)
+ : base (uri)
+ {
+ }
+
+ public CipherReference (string uri, TransformChain tc)
+ : base (uri, tc)
+ {
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ public override XmlElement GetXml ()
+ {
+ return GetXml (new XmlDocument ());
+ }
+
+ internal override XmlElement GetXml (XmlDocument document)
+ {
+ XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.CipherReference, XmlEncryption.NamespaceURI);
+
+ xel.SetAttribute (XmlEncryption.AttributeNames.URI, Uri);
+
+ if (TransformChain != null && TransformChain.Count > 0) {
+ XmlElement xtr = document.CreateElement (XmlEncryption.ElementNames.Transforms, XmlEncryption.NamespaceURI);
+ foreach (Transform t in TransformChain)
+ xtr.AppendChild (document.ImportNode (t.GetXml (), true));
+ xel.AppendChild (xtr);
+ }
+
+ return xel;
+ }
+
+ public override void LoadXml (XmlElement value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ if ((value.LocalName != XmlEncryption.ElementNames.CipherReference) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+ throw new CryptographicException ("Malformed CipherReference element.");
+ else {
+ Uri = null;
+ TransformChain = new TransformChain ();
+
+ foreach (XmlNode n in value.ChildNodes) {
+ if (n is XmlWhitespace)
+ continue;
+
+ switch (n.LocalName) {
+ case XmlEncryption.ElementNames.Transforms:
+ foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) {
+ Transform t = null;
+ switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) {
+ case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform:
+ t = new XmlDsigBase64Transform ();
+ break;
+ case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform:
+ t = new XmlDsigC14NTransform ();
+ break;
+ case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform:
+ t = new XmlDsigC14NWithCommentsTransform ();
+ break;
+ case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform:
+ t = new XmlDsigEnvelopedSignatureTransform ();
+ break;
+ case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform:
+ t = new XmlDsigXPathTransform ();
+ break;
+ case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform:
+ t = new XmlDsigXsltTransform ();
+ break;
+ default:
+ continue;
+ }
+
+ t.LoadInnerXml (((XmlElement) xn).ChildNodes);
+ TransformChain.Add (t);
+ }
+ break;
+ }
+ }
+
+ if (value.HasAttribute (XmlEncryption.AttributeNames.URI))
+ Uri = value.Attributes [XmlEncryption.AttributeNames.URI].Value;
+ }
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// EncryptedData.cs - EncryptedData implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptedData
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public sealed class EncryptedData : EncryptedType {
+
+ #region Constructors
+
+ public EncryptedData ()
+ : base ()
+ {
+ }
+
+ #endregion // Constructors
+
+ #region Methods
+
+ public override XmlElement GetXml ()
+ {
+ return GetXml (new XmlDocument ());
+ }
+
+ internal XmlElement GetXml (XmlDocument document)
+ {
+ if (CipherData == null)
+ throw new CryptographicException ("Cipher data is not specified.");
+
+ XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptedData, XmlEncryption.NamespaceURI);
+
+ 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, XmlEncryption.NamespaceURI);
+ 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;
+ }
+
+ public override void LoadXml (XmlElement value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ if ((value.LocalName != XmlEncryption.ElementNames.EncryptedData) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+ throw new CryptographicException ("Malformed EncryptedData element.");
+ else {
+ EncryptionMethod = null;
+ KeyInfo keyInfo = null;
+ CipherData cipherData = null;
+ EncryptionMethod = null;
+ EncryptionProperties = new EncryptionProperties ();
+ 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, XmlEncryption.NamespaceURI))
+ 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;
+ }
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// EncryptedReference.cs - EncryptedReference implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptedReference
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public abstract class EncryptedReference {
+
+ #region Fields
+
+ bool cacheValid;
+ string referenceType;
+ string uri;
+ TransformChain tc;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ protected EncryptedReference ()
+ {
+ uri = null;
+ TransformChain = new TransformChain ();
+ }
+
+ protected EncryptedReference (string uri)
+ {
+ Uri = uri;
+ TransformChain = new TransformChain ();
+ }
+
+ protected EncryptedReference (string uri, TransformChain tc)
+ : this ()
+ {
+ Uri = uri;
+ TransformChain = tc;
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ [MonoTODO()]
+ protected internal bool CacheValid {
+ get { return cacheValid; }
+ }
+
+ [MonoTODO]
+ protected string ReferenceType {
+ get { return referenceType; }
+ }
+
+ public TransformChain TransformChain {
+ get { return tc; }
+ set { tc = value; }
+ }
+
+ public string Uri {
+ get { return uri; }
+ set { uri = value; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public void AddTransform (Transform transform)
+ {
+ TransformChain.Add (transform);
+ }
+
+ public virtual XmlElement GetXml ()
+ {
+ return GetXml (new XmlDocument ());
+ }
+
+ internal virtual XmlElement GetXml (XmlDocument document)
+ {
+ return document.CreateElement ("", "");
+ }
+
+ public virtual void LoadXml (XmlElement value)
+ {
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// EncryptedType.cs - EncryptedType implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptedType
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public abstract class EncryptedType {
+
+ #region Fields
+
+ CipherData cipherData;
+ string encoding;
+ EncryptionMethod encryptionMethod;
+ EncryptionProperties encryptionProperties;
+ string id;
+ KeyInfo keyInfo;
+ string mimeType;
+ string type;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ protected EncryptedType ()
+ {
+ cipherData = null;
+ encoding = null;
+ encryptionMethod = null;
+ encryptionProperties = new EncryptionProperties ();
+ id = null;
+ keyInfo = null;
+ mimeType = null;
+ type = null;
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public virtual CipherData CipherData {
+ get { return cipherData; }
+ set { cipherData = value; }
+ }
+
+ public virtual string Encoding {
+ get { return encoding; }
+ set { encoding = value; }
+ }
+
+ public virtual EncryptionMethod EncryptionMethod {
+ get { return encryptionMethod; }
+ set { encryptionMethod = value; }
+ }
+
+ public virtual EncryptionProperties EncryptionProperties {
+ get { return encryptionProperties; }
+ set { encryptionProperties = value; }
+ }
+
+ public virtual string Id {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public KeyInfo KeyInfo {
+ get { return keyInfo; }
+ set { keyInfo = value; }
+ }
+
+ public virtual string MimeType {
+ get { return mimeType; }
+ set { mimeType = value; }
+ }
+
+ public virtual string Type {
+ get { return type; }
+ set { type = value; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public void AddProperty (EncryptionProperty ep)
+ {
+ EncryptionProperties.Add (ep);
+ }
+
+ public abstract XmlElement GetXml ();
+ public abstract void LoadXml (XmlElement value);
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// EncryptionMethod.cs - EncryptionMethod implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptionMethod
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public class EncryptionMethod {
+
+ #region Fields
+
+ string algorithm;
+ int keySize;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ public EncryptionMethod ()
+ {
+ KeyAlgorithm = null;
+ }
+
+ public EncryptionMethod (string strAlgorithm)
+ {
+ KeyAlgorithm = strAlgorithm;
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public string KeyAlgorithm {
+ get { return algorithm; }
+ set { algorithm = value; }
+ }
+
+ public int KeySize {
+ get { return keySize; }
+ set {
+ if (value <= 0)
+ throw new ArgumentOutOfRangeException ("The key size should be a non negative integer.");
+ keySize = value;
+ }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public XmlElement GetXml ()
+ {
+ return GetXml (new XmlDocument ());
+ }
+
+ internal XmlElement GetXml (XmlDocument document)
+ {
+ XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptionMethod, XmlEncryption.NamespaceURI);
+
+ if (KeySize != 0) {
+ XmlElement xks = document.CreateElement (XmlEncryption.ElementNames.KeySize, XmlEncryption.NamespaceURI);
+ xks.InnerText = String.Format ("{0}", keySize);
+ xel.AppendChild (xks);
+ }
+
+ if (KeyAlgorithm != null)
+ xel.SetAttribute (XmlEncryption.AttributeNames.Algorithm, KeyAlgorithm);
+ return xel;
+ }
+
+ public void LoadXml (XmlElement value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+ if ((value.LocalName != XmlEncryption.ElementNames.EncryptionMethod) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+ throw new CryptographicException ("Malformed EncryptionMethod element.");
+ else {
+ KeyAlgorithm = null;
+ foreach (XmlNode n in value.ChildNodes) {
+ if (n is XmlWhitespace)
+ continue;
+ switch (n.LocalName) {
+ case XmlEncryption.ElementNames.KeySize:
+ KeySize = Int32.Parse (n.InnerText);
+ break;
+ }
+ }
+ if (value.HasAttribute (XmlEncryption.AttributeNames.Algorithm))
+ KeyAlgorithm = value.Attributes [XmlEncryption.AttributeNames.Algorithm].Value;
+ }
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// EncryptionProperties.cs - EncryptionProperties implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptionProperties
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Collections;
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public sealed class EncryptionProperties : IList, ICollection, IEnumerable {
+
+ #region Fields
+
+ ArrayList list;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ public EncryptionProperties ()
+ {
+ list = new ArrayList ();
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public int Count {
+ get { return list.Count; }
+ }
+
+ public bool IsFixedSize {
+ get { return list.IsFixedSize; }
+ }
+
+ public bool IsReadOnly {
+ get { return list.IsReadOnly; }
+ }
+
+ public bool IsSynchronized {
+ get { return list.IsSynchronized; }
+ }
+
+ object IList.this [int index] {
+ get { return this [index]; }
+ set { this [index] = (EncryptionProperty) value; }
+ }
+
+ public EncryptionProperty this [int index] {
+ get { return (EncryptionProperty) list [index]; }
+ set { list [index] = value; }
+ }
+
+ public object SyncRoot {
+ get { return list.SyncRoot; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public int Add (EncryptionProperty value)
+ {
+ return list.Add (value);
+ }
+
+ public void Clear ()
+ {
+ list.Clear ();
+ }
+
+ public bool Contains (EncryptionProperty value)
+ {
+ return list.Contains (value);
+ }
+
+ public void CopyTo (Array array, int index)
+ {
+ list.CopyTo (array, index);
+ }
+
+ public void CopyTo (EncryptionProperty[] array, int index)
+ {
+ list.CopyTo (array, index);
+ }
+
+ public IEnumerator GetEnumerator ()
+ {
+ return list.GetEnumerator ();
+ }
+
+ bool IList.Contains (object value)
+ {
+ return Contains ((EncryptionProperty) value);
+ }
+
+ int IList.Add (object value)
+ {
+ return Add ((EncryptionProperty) value);
+ }
+
+ int IList.IndexOf (object value)
+ {
+ return IndexOf ((EncryptionProperty) value);
+ }
+
+ void IList.Insert (int index, object value)
+ {
+ Insert (index, (EncryptionProperty) value);
+ }
+
+ void IList.Remove (object value)
+ {
+ Remove ((EncryptionProperty) value);
+ }
+
+ public int IndexOf (EncryptionProperty value)
+ {
+ return list.IndexOf (value);
+ }
+
+ public void Insert (int index, EncryptionProperty value)
+ {
+ list.Insert (index, value);
+ }
+
+ public EncryptionProperty Item (int index)
+ {
+ return (EncryptionProperty) list [index];
+ }
+
+ public void Remove (EncryptionProperty value)
+ {
+ list.Remove (value);
+ }
+
+ public void RemoveAt (int index)
+ {
+ list.RemoveAt (index);
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
--- /dev/null
+//
+// EncryptionProperty.cs - EncryptionProperty implementation for XML Encryption
+// http://www.w3.org/2001/04/xmlenc#sec-EncryptionProperty
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+
+#if NET_1_2
+
+using System.Xml;
+
+namespace System.Security.Cryptography.Xml {
+ public sealed class EncryptionProperty {
+
+ #region Fields
+
+ XmlElement elemProp;
+ string id;
+ string target;
+
+ #endregion // Fields
+
+ #region Constructors
+
+ public EncryptionProperty ()
+ {
+ }
+
+ public EncryptionProperty (XmlElement elemProp)
+ {
+ LoadXml (elemProp);
+ }
+
+ #endregion // Constructors
+
+ #region Properties
+
+ public string Id {
+ get { return id; }
+ }
+
+ public XmlElement PropertyElement {
+ get { return elemProp; }
+ set { LoadXml (value); }
+ }
+
+ public string Target {
+ get { return target; }
+ }
+
+ #endregion // Properties
+
+ #region Methods
+
+ public XmlElement GetXml ()
+ {
+ return GetXml (new XmlDocument ());
+ }
+
+ internal XmlElement GetXml (XmlDocument document)
+ {
+ XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptionProperty, XmlEncryption.NamespaceURI);
+
+ if (Id != null)
+ xel.SetAttribute (XmlEncryption.AttributeNames.Id, Id);
+ if (Target != null)
+ xel.SetAttribute (XmlEncryption.AttributeNames.Target, Target);
+
+ return xel;
+ }
+
+ public void LoadXml (XmlElement value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ if ((value.LocalName != XmlEncryption.ElementNames.EncryptionProperty) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
+ throw new CryptographicException ("Malformed EncryptionProperty element.");
+ else {
+ if (value.HasAttribute (XmlEncryption.AttributeNames.Id))
+ this.id = value.Attributes [XmlEncryption.AttributeNames.Id].Value;
+ if (value.HasAttribute (XmlEncryption.AttributeNames.Target))
+ this.target = value.Attributes [XmlEncryption.AttributeNames.Target].Value;
+ }
+ }
+
+ #endregion // Methods
+ }
+}
+
+#endif
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
+// Tim Coleman (tim@timcoleman.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) Tim Coleman, 2004
//
using System.Xml;
private string URI;
+#if NET_1_2
+ string type;
+#endif
+
public KeyInfoRetrievalMethod () {}
public KeyInfoRetrievalMethod (string strUri)
URI = strUri;
}
+#if NET_1_2
+ public KeyInfoRetrievalMethod (string strUri, string strType)
+ : this (strUri)
+ {
+ Type = strType;
+ }
+
+ public string Type {
+ get { return type; }
+ set { type = value; }
+ }
+#endif
+
public string Uri {
get { return URI; }
set { URI = value; }
}
+
public override XmlElement GetXml ()
{
XmlDocument document = new XmlDocument ();
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.RetrievalMethod, XmlSignature.NamespaceURI);
if (URI != null)
xel.SetAttribute (XmlSignature.AttributeNames.URI, URI);
+#if NET_1_2
+ if (Type != null)
+ xel.SetAttribute (XmlSignature.AttributeNames.Type, Type);
+#endif
return xel;
}
if (value == null)
throw new ArgumentNullException ();
- if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI))
+ if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI)) {
URI = ""; // not null - so we return URI="" as attribute !!!
- else
+ } else {
URI = value.Attributes [XmlSignature.AttributeNames.URI].Value;
+#if NET_1_2
+ if (value.HasAttribute (XmlSignature.AttributeNames.Type))
+ Type = value.Attributes [XmlSignature.AttributeNames.Type].Value;
+#endif
+ }
}
}
-}
\ No newline at end of file
+}
--- /dev/null
+//
+// XmlEncryption.cs: Handles Xml Encryption
+//
+// Author:
+// Tim Coleman (tim@timcoleman.com)
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) Tim Coleman, 2004
+//
+
+#if NET_1_2
+
+using System;
+
+namespace System.Security.Cryptography.Xml {
+
+ // following the design of WSE
+ internal class XmlEncryption {
+
+ public class ElementNames {
+
+ public const string CipherData = "CipherData";
+ public const string CipherReference = "CipherReference";
+ public const string CipherValue = "CipherValue";
+ public const string EncryptedData = "EncryptedData";
+ public const string EncryptionMethod = "EncryptionMethod";
+ public const string EncryptionProperties = "EncryptionProperties";
+ public const string EncryptionProperty = "EncryptionProperty";
+ public const string KeySize = "KeySize";
+ public const string Transforms = "Transforms";
+
+ public ElementNames () {}
+ }
+
+ public class AttributeNames {
+
+ public const string Algorithm = "Algorithm";
+ public const string Encoding = "Encoding";
+ public const string Id = "Id";
+ public const string MimeType = "MimeType";
+ public const string Target = "Target";
+ public const string Type = "Type";
+ public const string URI = "URI";
+
+ public AttributeNames () {}
+ }
+
+ public const string NamespaceURI = "http://www.w3.org/2001/04/xmlenc#";
+ public const string Prefix = "xenc";
+
+ public XmlEncryption () {}
+ }
+}
+
+#endif
public AttributeNames () {}
}
+ public class AlgorithmNamespaces {
+ public const string XmlDsigBase64Transform = "http://www.w3.org/2000/09/xmldsig#base64";
+ public const string XmlDsigC14NTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
+ public const string XmlDsigC14NWithCommentsTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
+ public const string XmlDsigEnvelopedSignatureTransform = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
+ public const string XmlDsigXPathTransform = "http://www.w3.org/TR/1999/REC-xpath-19991116";
+ public const string XmlDsigXsltTransform = "http://www.w3.org/TR/1999/REC-xslt-19991116";
+ }
+
public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
public const string Prefix = "ds";