18 using System.Security.Cryptography;
20 namespace Deveel.Data.Security {
63 if (String.Equals(functionName,
"SHA256", StringComparison.OrdinalIgnoreCase) ||
64 String.Equals(functionName,
"SHA-256", StringComparison.OrdinalIgnoreCase))
67 if (String.Equals(functionName,
"SHA384", StringComparison.OrdinalIgnoreCase) ||
68 String.Equals(functionName,
"SHA-384", StringComparison.OrdinalIgnoreCase))
71 if (String.Equals(functionName,
"SHA512", StringComparison.OrdinalIgnoreCase) ||
72 String.Equals(functionName,
"SHA-512", StringComparison.OrdinalIgnoreCase))
75 if (String.Equals(functionName,
"MD5", StringComparison.OrdinalIgnoreCase))
78 if (String.Equals(functionName,
"SHA1", StringComparison.OrdinalIgnoreCase) ||
79 String.Equals(functionName,
"SHA-1", StringComparison.OrdinalIgnoreCase))
83 if (String.Equals(functionName,
"HMAC-SHA256", StringComparison.OrdinalIgnoreCase) ||
84 String.Equals(functionName,
"HMACSHA256", StringComparison.OrdinalIgnoreCase) ||
85 String.Equals(functionName,
"HMAC-SHA-256", StringComparison.OrdinalIgnoreCase))
88 if (String.Equals(functionName,
"HMAC-SHA384", StringComparison.OrdinalIgnoreCase) ||
89 String.Equals(functionName,
"HMACSHA384", StringComparison.OrdinalIgnoreCase) ||
90 String.Equals(functionName,
"HMAC-SHA-384", StringComparison.OrdinalIgnoreCase))
93 if (String.Equals(functionName,
"HMAC-SHA512", StringComparison.OrdinalIgnoreCase) ||
94 String.Equals(functionName,
"HMACSHA512", StringComparison.OrdinalIgnoreCase) ||
95 String.Equals(functionName,
"HMAC-SHA-512", StringComparison.OrdinalIgnoreCase))
98 if (String.Equals(functionName,
"HMAC-SHA1", StringComparison.OrdinalIgnoreCase) ||
99 String.Equals(functionName,
"HMACSHA1", StringComparison.OrdinalIgnoreCase) ||
100 String.Equals(functionName,
"HMAC-SHA-1", StringComparison.OrdinalIgnoreCase))
103 if (String.Equals(functionName,
"HMAC-MD5", StringComparison.OrdinalIgnoreCase) ||
104 String.Equals(functionName,
"HMACMD5", StringComparison.OrdinalIgnoreCase))
114 Hash = HashAlgorithm.Create(hashName);
117 throw new ArgumentException(String.Format(
"Hash function {0} is not supported", hashName));
120 private HashAlgorithm
Hash {
get; set; }
126 public int HashSize {
127 get {
return Hash.HashSize; }
131 return Hash.ComputeHash(data);
137 #region KeyedHashFunction
141 Hash = KeyedHashAlgorithm.Create(hashName);
144 throw new ArgumentException(String.Format(
"The hash function {0} is not supported", hashName));
147 private KeyedHashAlgorithm
Hash {
get; set; }
153 public int HashSize {
154 get {
return Hash.HashSize; }
158 return Hash.ComputeHash(data);
162 get {
return Hash.Key; }
163 set {
Hash.Key = value; }
byte[] Compute(byte[] data)
Computes the hash from the given input.
The hash of a password obtained from the configured hash mechanism, given an input password from the ...
byte[] Compute(byte[] data)
Computes the hash from the given input.
Defines a function to hash as user provided password
static IHashFunction GetFunction(string functionName)
HashFunction(string hashName)
An hash function that requires a private key to compute the final result.
KeyedHashFunction(string hashName)