using System.Security.Cryptography;
public static void Main()
Console.WriteLine(HmacSha256("tést", "xxx"));
Console.WriteLine(HMACSHA256Encrypt("tést", "xxx"));
public static string HmacSha256(string str, string key)
var arrKey = Encoding.UTF8.GetBytes(key);
var message = Encoding.UTF8.GetBytes(str);
var hmac = new HMACSHA256(arrKey);
return Convert.ToHexString(hmac.ComputeHash(message)).ToLower();
public static String HMACSHA256Encrypt(String text, String key)
Byte[] textBytes = Encoding.UTF8.GetBytes(text);
Byte[] keyBytes = Encoding.UTF8.GetBytes(key);
using (HMACSHA256 hash = new HMACSHA256(keyBytes))
hashBytes = hash.ComputeHash(textBytes);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();