using System;
using System.Text;
using System.Security.Cryptography;
namespace TestCSharpHMAC
{
public class Program
{
public static void Main(string[] args)
{
string hash = "";
string str = "hogehoge";
//HMAC鍵
string keySource = "qwertyuiopasdfghjklz";
byte[] HmacKey = Encoding.UTF8.GetBytes(keySource);
HMACSHA1 mac = new HMACSHA1(HmacKey);
byte[] hashValue = mac.ComputeHash(Encoding.UTF8.GetBytes(str));
hash = Convert.ToBase64String(hashValue);
Console.WriteLine(hash);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLlNlY3VyaXR5LkNyeXB0b2dyYXBoeTsKbmFtZXNwYWNlIFRlc3RDU2hhcnBITUFDCnsKICAgIHB1YmxpYyBjbGFzcyBQcm9ncmFtCiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oc3RyaW5nW10gYXJncykKICAgICAgICB7CiAgICAgICAgICAgIHN0cmluZyBoYXNoID0gIiI7CiAgICAgICAgICAgIHN0cmluZyBzdHIgPSAiaG9nZWhvZ2UiOwogICAgICAgICAgICAvL0hNQUPpjbUKICAgICAgICAgICAgc3RyaW5nIGtleVNvdXJjZSA9ICJxd2VydHl1aW9wYXNkZmdoamtseiI7CiAgICAgICAgICAgIGJ5dGVbXSBIbWFjS2V5ID0gRW5jb2RpbmcuVVRGOC5HZXRCeXRlcyhrZXlTb3VyY2UpOwogICAgICAgICAgICBITUFDU0hBMSBtYWMgPSBuZXcgSE1BQ1NIQTEoSG1hY0tleSk7CiAgICAgICAgICAgIGJ5dGVbXSBoYXNoVmFsdWUgPSBtYWMuQ29tcHV0ZUhhc2goRW5jb2RpbmcuVVRGOC5HZXRCeXRlcyhzdHIpKTsKICAgICAgICAgICAgaGFzaCA9IENvbnZlcnQuVG9CYXNlNjRTdHJpbmcoaGFzaFZhbHVlKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoaGFzaCk7CiAgICAgICAgfQogICAgfQp9Cg==