1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
//
// System.Security.Cryptography.CngAlgorithm
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.Security.Cryptography {
// note: CNG stands for "Cryptography API: Next Generation"
[Serializable]
public sealed class CngAlgorithm : IEquatable<CngAlgorithm> {
private string algo;
public CngAlgorithm (string algorithm)
{
if (algorithm == null)
throw new ArgumentNullException ("algorithm");
if (algorithm.Length == 0)
throw new ArgumentException ("algorithm");
algo = algorithm;
}
public string Algorithm {
get { return algo; }
}
public bool Equals (CngAlgorithm other)
{
if (other == null)
return false;
return algo == other.algo;
}
public override bool Equals (object obj)
{
return Equals (obj as CngAlgorithm);
}
public override int GetHashCode ()
{
return algo.GetHashCode ();
}
public override string ToString ()
{
return algo;
}
// static
static CngAlgorithm dh256;
static CngAlgorithm dh384;
static CngAlgorithm dh521;
static CngAlgorithm dsa256;
static CngAlgorithm dsa384;
static CngAlgorithm dsa521;
static CngAlgorithm md5;
static CngAlgorithm sha1;
static CngAlgorithm sha256;
static CngAlgorithm sha384;
static CngAlgorithm sha512;
public static CngAlgorithm ECDiffieHellmanP256 {
get {
if (dh256 == null)
dh256 = new CngAlgorithm ("ECDH_P256");
return dh256;
}
}
public static CngAlgorithm ECDiffieHellmanP384 {
get {
if (dh384 == null)
dh384 = new CngAlgorithm ("ECDH_P384");
return dh384;
}
}
public static CngAlgorithm ECDiffieHellmanP521 {
get {
if (dh521 == null)
dh521 = new CngAlgorithm ("ECDH_P521");
return dh521;
}
}
public static CngAlgorithm ECDsaP256 {
get {
if (dsa256 == null)
dsa256 = new CngAlgorithm ("ECDSA_P256");
return dsa256;
}
}
public static CngAlgorithm ECDsaP384 {
get {
if (dsa384 == null)
dsa384 = new CngAlgorithm ("ECDSA_P384");
return dsa384;
}
}
public static CngAlgorithm ECDsaP521 {
get {
if (dsa521 == null)
dsa521 = new CngAlgorithm ("ECDSA_P521");
return dsa521;
}
}
public static CngAlgorithm MD5 {
get {
if (md5 == null)
md5 = new CngAlgorithm ("MD5");
return md5;
}
}
public static CngAlgorithm Sha1 {
get {
if (sha1 == null)
sha1 = new CngAlgorithm ("SHA1");
return sha1;
}
}
public static CngAlgorithm Sha256 {
get {
if (sha256 == null)
sha256 = new CngAlgorithm ("SHA256");
return sha256;
}
}
public static CngAlgorithm Sha384 {
get {
if (sha384 == null)
sha384 = new CngAlgorithm ("SHA384");
return sha384;
}
}
public static CngAlgorithm Sha512 {
get {
if (sha512 == null)
sha512 = new CngAlgorithm ("SHA512");
return sha512;
}
}
public static bool operator == (CngAlgorithm left, CngAlgorithm right)
{
if ((object)left == null)
return ((object)right == null);
if ((object)right == null)
return false;
return left.algo == right.algo;
}
public static bool operator != (CngAlgorithm left, CngAlgorithm right)
{
if ((object)left == null)
return ((object)right != null);
if ((object)right == null)
return true;
return left.algo != right.algo;
}
}
}
|