skynyrd
3/6/2017 - 7:52 PM

Hash with HMACSHA1

Hash with HMACSHA1

//C#, Security, Crypt

public static string HashWithHMACSHA1(string secret, string toBeHashed)
{
    var secretBytes = Encoding.UTF8.GetBytes(secret);
    var hmac = new HMACSHA1(secretBytes);

    var dataBytes = Encoding.UTF8.GetBytes(toBeHashed);
    var calcHash = hmac.ComputeHash(dataBytes);
    var calcHashString = Convert.ToBase64String(calcHash);
    return calcHashString;
}