HMACSHA256编码:
private static string GeneratePrivateKey(string secret, string orignalStr)
{
try
{
if (string.IsNullOrEmpty(secret))
throw new ArgumentException("密钥不能为空!");
using (var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(secret)))
{
byte[] hashmessage = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(orignalStr));
return HttpUtility.UrlEncode(Convert.ToBase64String(hashmessage), Encoding.UTF8);
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
