using System;
using System.Text;
using System.Security.Cryptography;
public class Program
{
private const string key = "key";
private const string message = "message";
private static readonly Encoding encoding = Encoding.UTF8;
static void Main(string[] args)
{
var keyByte = encoding.GetBytes(key);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
hmacsha256.ComputeHash(encoding.GetBytes(message));
Console.WriteLine("Result: {0}", ByteToString(hmacsha256.Hash));
}
}
static string ByteToString(byte[] buff)
{
string sbinary = "";
for (int i = 0; i < buff.Length; i++)
sbinary += buff[i].ToString("X2"); /* hex format */
return sbinary;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLlNlY3VyaXR5LkNyeXB0b2dyYXBoeTsKCnB1YmxpYyBjbGFzcyBQcm9ncmFtCnsKICAgIHByaXZhdGUgY29uc3Qgc3RyaW5nIGtleSA9ICJrZXkiOwogICAgcHJpdmF0ZSBjb25zdCBzdHJpbmcgbWVzc2FnZSA9ICJtZXNzYWdlIjsKICAgIHByaXZhdGUgc3RhdGljIHJlYWRvbmx5IEVuY29kaW5nIGVuY29kaW5nID0gRW5jb2RpbmcuVVRGODsgCgogICAgc3RhdGljIHZvaWQgTWFpbihzdHJpbmdbXSBhcmdzKQogICAgewogICAgICAgIHZhciBrZXlCeXRlID0gZW5jb2RpbmcuR2V0Qnl0ZXMoa2V5KTsKICAgICAgICB1c2luZyAodmFyIGhtYWNzaGEyNTYgPSBuZXcgSE1BQ1NIQTI1NihrZXlCeXRlKSkKICAgICAgICB7CiAgICAgICAgICAgIGhtYWNzaGEyNTYuQ29tcHV0ZUhhc2goZW5jb2RpbmcuR2V0Qnl0ZXMobWVzc2FnZSkpOwoKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIlJlc3VsdDogezB9IiwgQnl0ZVRvU3RyaW5nKGhtYWNzaGEyNTYuSGFzaCkpOwogICAgICAgICB9CiAgICB9CiAgICBzdGF0aWMgc3RyaW5nIEJ5dGVUb1N0cmluZyhieXRlW10gYnVmZikKICAgIHsKICAgICAgICBzdHJpbmcgc2JpbmFyeSA9ICIiOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYnVmZi5MZW5ndGg7IGkrKykKICAgICAgICAgICAgc2JpbmFyeSArPSBidWZmW2ldLlRvU3RyaW5nKCJYMiIpOyAvKiBoZXggZm9ybWF0ICovCiAgICAgICAgcmV0dXJuIHNiaW5hcnk7CiAgICB9ICAgIAp9Cg==