using System;
using System.Text;
using System.Security.Cryptography;
class Program
{
static void Main()
{
string secret = "your-secret-key";
string message = "your-message-to-hash";
using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret)))
{
byte[] hashMessage = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
string hashString = BitConverter.ToString(hashMessage).Replace("-", "").ToLower();
Console.WriteLine("HMAC SHA256: " + hashString);
}
}
}
System, System.Text, 和 System.Security.Cryptography 是必要的命名空间,用于处理字符串编码和加密操作。secret 是用于生成 HMAC 的密钥,message 是要哈希的消息。HMACSHA256 对象。ComputeHash 方法计算消息的哈希值。-),最后转换为小写。希望这段代码和解释对你有帮助!
上一篇:c# console
下一篇:c#序列化
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站