2 // EncryptionMethod.cs - EncryptionMethod implementation for XML Encryption
3 // http://www.w3.org/2001/04/xmlenc#sec-EncryptionMethod
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Tim Coleman, 2004
14 namespace System.Security.Cryptography.Xml {
15 public class EncryptionMethod {
26 public EncryptionMethod ()
31 public EncryptionMethod (string strAlgorithm)
33 KeyAlgorithm = strAlgorithm;
36 #endregion // Constructors
40 public string KeyAlgorithm {
41 get { return algorithm; }
42 set { algorithm = value; }
46 get { return keySize; }
49 throw new ArgumentOutOfRangeException ("The key size should be a non negative integer.");
54 #endregion // Properties
58 public XmlElement GetXml ()
60 return GetXml (new XmlDocument ());
63 internal XmlElement GetXml (XmlDocument document)
65 XmlElement xel = document.CreateElement (XmlEncryption.ElementNames.EncryptionMethod, XmlEncryption.NamespaceURI);
68 XmlElement xks = document.CreateElement (XmlEncryption.ElementNames.KeySize, XmlEncryption.NamespaceURI);
69 xks.InnerText = String.Format ("{0}", keySize);
70 xel.AppendChild (xks);
73 if (KeyAlgorithm != null)
74 xel.SetAttribute (XmlEncryption.AttributeNames.Algorithm, KeyAlgorithm);
78 public void LoadXml (XmlElement value)
81 throw new ArgumentNullException ("value");
82 if ((value.LocalName != XmlEncryption.ElementNames.EncryptionMethod) || (value.NamespaceURI != XmlEncryption.NamespaceURI))
83 throw new CryptographicException ("Malformed EncryptionMethod element.");
86 foreach (XmlNode n in value.ChildNodes) {
87 if (n is XmlWhitespace)
89 switch (n.LocalName) {
90 case XmlEncryption.ElementNames.KeySize:
91 KeySize = Int32.Parse (n.InnerText);
95 if (value.HasAttribute (XmlEncryption.AttributeNames.Algorithm))
96 KeyAlgorithm = value.Attributes [XmlEncryption.AttributeNames.Algorithm].Value;
100 #endregion // Methods