/// <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); } }