using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace AlicizaX { public static partial class Utility { /// /// 哈希计算相关的实用函数。 /// public static partial class Hash { /// /// HMACSha256 /// public static class HMACSha256 { /// /// 使用提供的密钥对指定消息进行HMACSHA256哈希计算。 /// /// 要进行哈希计算的消息。 /// 用于哈希计算的密钥。 /// Base64编码的哈希值。 public static string Hash(string message, string key) { byte[] keyBytes = Encoding.UTF8.GetBytes(key); byte[] messageBytes = Encoding.UTF8.GetBytes(message); using (var hmac = new HMACSHA256(keyBytes)) { byte[] hashBytes = hmac.ComputeHash(messageBytes); return Convert.ToBase64String(hashBytes); } } } } } }