C# HMACSHA256加密

/// <summary>
/// hmacsha256加密
/// </summary>
/// <param name="message">内容</param>
/// <param name="secret">密钥</param>
/// <param name="encoding">你懂的</param>
/// <returns></returns>
public static string HMACSHA256(string message, string secret, Encoding encoding)
{
    byte[] keyByte = encoding.GetBytes(secret);
    byte[] messageBytes = encoding.GetBytes(message);
    using (var hmacsha256 = new HMACSHA256(keyByte))
    {
        byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
        return Convert.ToBase64String(hashmessage);
    }
}

 

posted on 2021-06-22 15:23  炼金师  阅读(1059)  评论(0编辑  收藏  举报

导航