csharp HMACSHA256来自http://ideone.com/JdpeL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp HMACSHA256来自http://ideone.com/JdpeL相关的知识,希望对你有一定的参考价值。

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

public class Program
{
    private const string key = "key";
    private const string message = "message";
    private static readonly Encoding encoding = Encoding.UTF8; 

    static void Main(string[] args)
    {
        var keyByte = encoding.GetBytes(key);
        using (var hmacsha256 = new HMACSHA256(keyByte))
        {
            hmacsha256.ComputeHash(encoding.GetBytes(message));

            Console.WriteLine("Result: {0}", ByteToString(hmacsha256.Hash));
         }
    }
    static string ByteToString(byte[] buff)
    {
        string sbinary = "";
        for (int i = 0; i < buff.Length; i++)
            sbinary += buff[i].ToString("X2"); /* hex format */
        return sbinary;
    }    
}

以上是关于csharp HMACSHA256来自http://ideone.com/JdpeL的主要内容,如果未能解决你的问题,请参考以下文章

HmacSHA256 算法

Oracle 等效于 C# HMACSHA256

HMACSHA256 Class

hmac-sha256 2021-11-02

c#和java - hmacsha256 hash之间的区别

hmac sha256和sha256的区别