我正在尝试将此Node.js代码重新创建为C#。但是,结果不符合期望值。我认为是因为我需要像nodejs一样实现摘要功能。但是我不知道摘要实际上是如何工作的
========================================
var shaBody = crypto.createHmac('SHA256', base64Key)
.update(message);
var digestBody = shaBody.digest('base64');
console.log('Base64 Digest HMACSHA256 message: '+ digestBody);
========================================
byte[] secretkey = new Byte[64];
ASCIIEncoding encoding = new ASCIIEncoding();
string base64String = Convert.ToBase64String(encoding.GetBytes(authKey));
secretkey = Convert.FromBase64String(base64String);
byte[] requestBody = new Byte[64];
requestBody =
Convert.FromBase64String(Convert.ToBase64String(encoding.GetBytes(body)));
using (HMACSHA256 hmac = new HMACSHA256(secretkey))
{
byte[] hashValue = hmac.ComputeHash(requestBody);
var hex = BitConverter.ToString(hashValue).Replace("-",
"").ToLower();
string requestSignatureBase64String =
Convert.ToBase64String(hashValue);
Console.WriteLine(base64String);
Console.WriteLine(hex);
Console.WriteLine(requestSignatureBase64String);
}