using System.Collections.Generic;
using System.Security.Cryptography;
public static void Main()
var hash = CreateHash(input);
Console.WriteLine($"Key: {hash.Key.Length} bytes");
Console.WriteLine($"Data: {hash.Data.Length} bytes");
Console.WriteLine("-----------------------------------------------------");
var areEqual = VerifyHash(input, hash.Key, hash.Data);
Console.WriteLine($"Are equivalent: {areEqual}");
static (byte[] Key, byte[] Data) CreateHash(string input)
using var alg = new HMACSHA512();
return (alg.Key, alg.ComputeHash(Encoding.UTF8.GetBytes(input)));
static bool VerifyHash(string input, byte[] key, byte[] data)
using var alg = new HMACSHA512(key);
var computedData = alg.ComputeHash(Encoding.UTF8.GetBytes(input));
return new HashSet<byte>(computedData).SetEquals(data);
static void DumpArray(byte[] bytes, int bytesPerLine = 16)
StringBuilder sb = new StringBuilder();
for (int line = 0; line < bytes.Length; line += bytesPerLine)
var lineBytes = bytes.Skip(line).Take(bytesPerLine).ToArray();
sb.AppendFormat("{0:x8}: ", line);
sb.Append(string.Join(" ", lineBytes.Select(b => b.ToString("X2")).ToArray()).PadRight(bytesPerLine * 3));
sb.AppendLine(new string(lineBytes.Select(b => b < 32 ? '.' : (char)b).ToArray()));
Console.Write(sb.ToString());