2 // System.Security.Cryptography SignatureDescription Class implementation
5 // Thomas Neidhart (tome@sbox.tugraz.at)
6 // Sebastien Pouliot (spouliot@motus.com)
8 // Portions (C) 2002 Motus Technologies Inc. (http://www.motus.com)
12 // There seems to be some (internal?) class inheriting from SignatureDescription
13 // http://www.csharpfriends.com/Members/Main/Classes/get_class.aspx?assembly=mscorlib,%20Version=1.0.3300.0,%20Culture=neutral,%20PublicKeyToken=b77a5c561934e089&namespace=System.Security.Cryptography&class=SignatureDescription
14 // Those 2 classes are returned by CryptoConfig.CreateFromName and used in XMLDSIG
17 using System.Security;
19 namespace System.Security.Cryptography {
21 public class SignatureDescription {
22 private string _DeformatterAlgorithm;
23 private string _DigestAlgorithm;
24 private string _FormatterAlgorithm;
25 private string _KeyAlgorithm;
27 public SignatureDescription () {}
29 /// LAMESPEC: ArgumentNullException is thrown (not CryptographicException)
30 [MonoTODO("Parse SecurityElement")]
31 public SignatureDescription (SecurityElement el)
34 throw new ArgumentNullException ();
35 // TODO: Parse the SecurityElement
36 // Clearly it must contains Deformatter, Digest,
37 // Formatter and KeyAlgorithm...
38 // But what do the SecurityElement looks like ?
41 // There are no validation of the property
42 public string DeformatterAlgorithm {
43 get { return _DeformatterAlgorithm; }
44 set { _DeformatterAlgorithm = value; }
47 // There are no validation of the property
48 public string DigestAlgorithm {
49 get { return _DigestAlgorithm; }
50 set { _DigestAlgorithm = value; }
53 // There are no validation of the property
54 public string FormatterAlgorithm {
55 get { return _FormatterAlgorithm; }
56 set { _FormatterAlgorithm = value; }
59 // There are no validation of the property
60 public string KeyAlgorithm {
61 get { return _KeyAlgorithm; }
62 set { _KeyAlgorithm = value; }
65 public virtual AsymmetricSignatureDeformatter CreateDeformatter (AsymmetricAlgorithm key)
67 if (_DeformatterAlgorithm == null)
68 throw new ArgumentNullException ("DeformatterAlgorithm");
70 // this should throw the InvalidCastException if we have an invalid class
71 // (but not if the class doesn't exist - as null is valid for AsymmetricSignatureDeformatter)
72 AsymmetricSignatureDeformatter def = (AsymmetricSignatureDeformatter) CryptoConfig.CreateFromName (_DeformatterAlgorithm);
74 if (_KeyAlgorithm == null)
75 throw new NullReferenceException ("KeyAlgorithm");
82 /// Create the hash algorithm assigned with this object
84 public virtual HashAlgorithm CreateDigest ()
86 if (_DigestAlgorithm == null)
87 throw new ArgumentNullException ("DigestAlgorithm");
88 return (HashAlgorithm) CryptoConfig.CreateFromName (_DigestAlgorithm);
91 public virtual AsymmetricSignatureFormatter CreateFormatter (AsymmetricAlgorithm key)
93 if (_FormatterAlgorithm == null)
94 throw new ArgumentNullException ("FormatterAlgorithm");
96 // this should throw the InvalidCastException if we have an invalid class
97 // (but not if the class doesn't exist - as null is valid for AsymmetricSignatureDeformatter)
98 AsymmetricSignatureFormatter fmt = (AsymmetricSignatureFormatter) CryptoConfig.CreateFromName (_FormatterAlgorithm);
100 if (_KeyAlgorithm == null)
101 throw new NullReferenceException ("KeyAlgorithm");
107 } // SignatureDescription
109 internal class DSASignatureDescription : SignatureDescription {
110 public DSASignatureDescription ()
112 DeformatterAlgorithm = "System.Security.Cryptography.DSASignatureDeformatter";
113 DigestAlgorithm = "System.Security.Cryptography.SHA1CryptoServiceProvider";
114 FormatterAlgorithm = "System.Security.Cryptography.DSASignatureFormatter";
115 KeyAlgorithm = "System.Security.Cryptography.DSACryptoServiceProvider";
119 internal class RSAPKCS1SHA1SignatureDescription : SignatureDescription {
120 public RSAPKCS1SHA1SignatureDescription ()
122 DeformatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureDeformatter";
123 DigestAlgorithm = "System.Security.Cryptography.SHA1CryptoServiceProvider";
124 FormatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureFormatter";
125 KeyAlgorithm = "System.Security.Cryptography.RSACryptoServiceProvider";
128 public override AsymmetricSignatureDeformatter CreateDeformatter (AsymmetricAlgorithm key)
130 // just to please corcompare
131 return base.CreateDeformatter (key);
135 } // System.Security.Cryptography