2 // System.Security.Cryptography.CngAlgorithm
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 namespace System.Security.Cryptography {
33 // note: CNG stands for "Cryptography API: Next Generation"
36 public sealed class CngAlgorithm : IEquatable<CngAlgorithm> {
38 private string m_algorithm;
40 public CngAlgorithm (string algorithm)
42 if (algorithm == null)
43 throw new ArgumentNullException ("algorithm");
44 if (algorithm.Length == 0)
45 throw new ArgumentException ("algorithm");
47 m_algorithm = algorithm;
50 public string Algorithm {
51 get { return m_algorithm; }
54 public bool Equals (CngAlgorithm other)
58 return m_algorithm == other.m_algorithm;
61 public override bool Equals (object obj)
63 return Equals (obj as CngAlgorithm);
66 public override int GetHashCode ()
68 return m_algorithm.GetHashCode ();
71 public override string ToString ()
78 static CngAlgorithm dh256;
79 static CngAlgorithm dh384;
80 static CngAlgorithm dh521;
81 static CngAlgorithm dsa256;
82 static CngAlgorithm dsa384;
83 static CngAlgorithm dsa521;
84 static CngAlgorithm md5;
85 static CngAlgorithm sha1;
86 static CngAlgorithm sha256;
87 static CngAlgorithm sha384;
88 static CngAlgorithm sha512;
90 public static CngAlgorithm ECDiffieHellmanP256 {
93 dh256 = new CngAlgorithm ("ECDH_P256");
98 public static CngAlgorithm ECDiffieHellmanP384 {
101 dh384 = new CngAlgorithm ("ECDH_P384");
106 public static CngAlgorithm ECDiffieHellmanP521 {
109 dh521 = new CngAlgorithm ("ECDH_P521");
114 public static CngAlgorithm ECDsaP256 {
117 dsa256 = new CngAlgorithm ("ECDSA_P256");
122 public static CngAlgorithm ECDsaP384 {
125 dsa384 = new CngAlgorithm ("ECDSA_P384");
130 public static CngAlgorithm ECDsaP521 {
133 dsa521 = new CngAlgorithm ("ECDSA_P521");
138 public static CngAlgorithm MD5 {
141 md5 = new CngAlgorithm ("MD5");
146 public static CngAlgorithm Sha1 {
149 sha1 = new CngAlgorithm ("SHA1");
154 public static CngAlgorithm Sha256 {
157 sha256 = new CngAlgorithm ("SHA256");
162 public static CngAlgorithm Sha384 {
165 sha384 = new CngAlgorithm ("SHA384");
170 public static CngAlgorithm Sha512 {
173 sha512 = new CngAlgorithm ("SHA512");
178 public static bool operator == (CngAlgorithm left, CngAlgorithm right)
180 if ((object)left == null)
181 return ((object)right == null);
182 return left.Equals (right);
185 public static bool operator != (CngAlgorithm left, CngAlgorithm right)
187 if ((object)left == null)
188 return ((object)right != null);
189 return !left.Equals (right);