$request["merchantSig"] = base64_encode(pack("H*",hash_hmac('sha1',$message, $hmacKey)));
我试图将这个PHP代码转换为c#,但它无法正常工作
这是我的尝试
public static void CreateMerchantSignature(this PaymentVerificationDetail detail)
{
string hmacKey = "test";
string message
string merchantSignature = Base64Encode(ShaHash(message, hmacKey));
}
private static string ShaHash(string value, string key)
{
using (var hmac = new HMACSHA1(Encoding.ASCII.GetBytes(key)))
{
return ByteToString(hmac.ComputeHash(Encoding.ASCII.GetBytes(value)));
}
}
private static string ByteToString(IEnumerable<byte> data)
{
return string.Concat(data.Select(b => b.ToString("H*")));
}
public static string Base64Encode(string sha1EncryptedKey)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(sha1EncryptedKey);
return System.Convert.ToBase64String(plainTextBytes);
}
我做错了,无法理解。