在C#中,可以使用System.Security.Cryptography.HMACSHA256类来实现Java中的hmacHex方法。下面是一个示例代码:

using System;
using System.Security.Cryptography;
using System.Text;

public class Program
{
    public static void Main(string[] args)
    {
        string key = "your_key";
        string valueToDigest = "your_value";

        string hexDigest = HmacHex(key, valueToDigest);
        Console.WriteLine(hexDigest);
    }

    public static string HmacHex(string key, string valueToDigest)
    {
        byte[] keyBytes = Encoding.UTF8.GetBytes(key);
        byte[] valueBytes = Encoding.UTF8.GetBytes(valueToDigest);

        using (HMACSHA256 hmac = new HMACSHA256(keyBytes))
        {
            byte[] hashBytes = hmac.ComputeHash(valueBytes);
            return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
        }
    }
}

请将your_key替换为你的密钥,your_value替换为要计算哈希摘要的字符串。运行代码后,将输出哈希摘要的十六进制字符串

Java 的 hmacHexString valueToDigest 方法转C#

原文地址: https://www.cveoy.top/t/topic/hJCS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录