2using System.Collections.Generic;
5using System.Threading.Tasks;
6using System.Security.Cryptography;
78 StringBuilder Response =
new StringBuilder();
81 foreach (
byte b
in Data)
91 Response.Append(b.ToString(
"x2"));
94 return Response.ToString();
104 using (MemoryStream Bytes =
new MemoryStream())
111 for (i = 0; i < c; i++)
115 if (ch >=
'0' && ch <=
'9')
116 b2 = (byte)(ch -
'0');
117 else if (ch >=
'a' && ch <=
'f')
118 b2 = (byte)(ch -
'a' + 10);
119 else if (ch >=
'A' && ch <=
'F')
120 b2 = (byte)(ch -
'A' + 10);
121 else if (ch ==
' ' || ch == 160)
144 return Bytes.ToArray();
174 throw new ArgumentException(
"Unrecognized hash function", nameof(Function));
204 throw new ArgumentException(
"Unrecognized hash function", nameof(Function));
234 throw new ArgumentException(
"Unrecognized hash function", nameof(Function));
264 throw new ArgumentException(
"Unrecognized hash function", nameof(Function));
298 using (SHA1 SHA1 = SHA1.Create())
300 Result = SHA1.ComputeHash(Data);
315 using (SHA1 SHA1 = SHA1.Create())
317 Result = SHA1.ComputeHash(Data);
352 using (SHA256 SHA256 = SHA256.Create())
354 Result = SHA256.ComputeHash(Data);
369 using (SHA256 SHA256 = SHA256.Create())
371 Result = SHA256.ComputeHash(Data);
406 using (SHA384 SHA384 = SHA384.Create())
408 Result = SHA384.ComputeHash(Data);
423 using (SHA384 SHA384 = SHA384.Create())
425 Result = SHA384.ComputeHash(Data);
460 using (SHA512 SHA512 = SHA512.Create())
462 Result = SHA512.ComputeHash(Data);
477 using (SHA512 SHA512 = SHA512.Create())
479 Result = SHA512.ComputeHash(Data);
514 using (MD5 MD5 = MD5.Create())
516 Result = MD5.ComputeHash(Data);
531 using (MD5 MD5 = MD5.Create())
533 Result = MD5.ComputeHash(Data);
560 using (HMACSHA1 HMACSHA1 =
new HMACSHA1(Key))
562 Result = HMACSHA1.ComputeHash(Data);
589 using (HMACSHA256 HMACSHA256 =
new HMACSHA256(Key))
591 Result = HMACSHA256.ComputeHash(Data);
618 using (HMACSHA384 HMACSHA384 =
new HMACSHA384(Key))
620 Result = HMACSHA384.ComputeHash(Data);
647 using (HMACSHA512 HMACSHA512 =
new HMACSHA512(Key))
649 Result = HMACSHA512.ComputeHash(Data);
Contains methods for simple hash calculations.
static string ComputeSHA512HashString(byte[] Data)
Computes the SHA-512 hash of a block of binary data.
static string ComputeHMACSHA512HashString(byte[] Key, byte[] Data)
Computes the HMAC-SHA-512 hash of a block of binary data.
static string BinaryToString(byte[] Data, bool SpaceDelimiter)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
static byte[] ComputeSHA384Hash(Stream Data)
Computes the SHA-384 hash of a block of binary data.
static string ComputeSHA384HashString(byte[] Data)
Computes the SHA-384 hash of a block of binary data.
static string ComputeSHA512HashString(Stream Data)
Computes the SHA-512 hash of a block of binary data.
static string ComputeHashString(HashFunction Function, byte[] Data)
Computes a hash of a block of binary data.
static byte[] ComputeSHA256Hash(Stream Data)
Computes the SHA-256 hash of a block of binary data.
static string ComputeHMACSHA384HashString(byte[] Key, byte[] Data)
Computes the HMAC-SHA-384 hash of a block of binary data.
static byte[] ComputeSHA384Hash(byte[] Data)
Computes the SHA-384 hash of a block of binary data.
static string ComputeHMACSHA256HashString(byte[] Key, byte[] Data)
Computes the HMAC-SHA-256 hash of a block of binary data.
static string ComputeHMACSHA1HashString(byte[] Key, byte[] Data)
Computes the HMAC-SHA-1 hash of a block of binary data.
static byte[] ComputeHMACSHA1Hash(byte[] Key, byte[] Data)
Computes the HMAC-SHA-1 hash of a block of binary data.
static byte[] ComputeHash(HashFunction Function, Stream Data)
Computes a hash of a block of binary data.
static string ComputeSHA384HashString(Stream Data)
Computes the SHA-384 hash of a block of binary data.
static byte[] ComputeSHA1Hash(byte[] Data)
Computes the SHA-1 hash of a block of binary data.
static string ComputeSHA256HashString(byte[] Data)
Computes the SHA-256 hash of a block of binary data.
static byte[] StringToBinary(string s)
Parses a hex string.
static byte[] ComputeSHA512Hash(byte[] Data)
Computes the SHA-512 hash of a block of binary data.
static string ComputeHashString(HashFunction Function, Stream Data)
Computes a hash of a block of binary data.
static string BinaryToString(byte[] Data)
Converts an array of bytes to a string with their hexadecimal representations (in lower case).
static byte[] ComputeHMACSHA256Hash(byte[] Key, byte[] Data)
Computes the HMAC-SHA-256 hash of a block of binary data.
static byte[] ComputeMD5Hash(Stream Data)
Computes the MD5 hash of a block of binary data.
static byte[] ComputeHMACSHA512Hash(byte[] Key, byte[] Data)
Computes the HMAC-SHA-512 hash of a block of binary data.
static byte[] ComputeSHA512Hash(Stream Data)
Computes the SHA-512 hash of a block of binary data.
static byte[] ComputeSHA1Hash(Stream Data)
Computes the SHA-1 hash of a block of binary data.
static string ComputeSHA1HashString(Stream Data)
Computes the SHA-1 hash of a block of binary data.
static string ComputeMD5HashString(Stream Data)
Computes the MD5 hash of a block of binary data.
static byte[] ComputeSHA256Hash(byte[] Data)
Computes the SHA-256 hash of a block of binary data.
static string ComputeSHA1HashString(byte[] Data)
Computes the SHA-1 hash of a block of binary data.
static string ComputeSHA256HashString(Stream Data)
Computes the SHA-256 hash of a block of binary data.
static byte[] ComputeHMACSHA384Hash(byte[] Key, byte[] Data)
Computes the HMAC-SHA-384 hash of a block of binary data.
static byte[] ComputeMD5Hash(byte[] Data)
Computes the MD5 hash of a block of binary data.
static string ComputeMD5HashString(byte[] Data)
Computes the MD5 hash of a block of binary data.
static byte[] ComputeHash(HashFunction Function, byte[] Data)
Computes a hash of a block of binary data.
delegate byte[] HashFunctionStream(Stream Data)
Delegate to hash function.
delegate byte[] HashFunctionArray(byte[] Data)
Delegate to hash function.
HashFunction
Hash method enumeration.