我在 PHP 中有一个代码,当我执行下面的 PHP 代码时,当我运行 PHP 代码下面的 C# 代码时,我得到了不同的结果,我不知道我错在哪里。
$accessID = "member-1681fca809";
$secretKey = "63f22236ab43b69462b3272b110e3c78";
$expires = 1357039353;
$stringToSign = $accessID."\n".$expires;
$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
$urlSafeSignature = urlencode(base64_encode($binarySignature));
print_r($expires);
print_r($urlSafeSignature);
I got Output
1357039353
M1PZW2DYVzdRV1l4ZHBPAmiv9iM%3D
当我在 c# 中运行相同的代码时,我得到了不同的输出
string accessid = "member-1681fca809";
string secretekey = "63f22236ab43b69462b3272b110e3c78";
int Expire = 1357039353;
string stringTosign = accessid + Environment.NewLine + Expire;
byte[] secret = UTF8Encoding.UTF8.GetBytes(secretekey);
HMACSHA1 myhmacsha1 = new HMACSHA1(secret);
byte[] byteArray = Encoding.ASCII.GetBytes(stringTosign);
MemoryStream stream = new MemoryStream(byteArray);
byte[] hashValue = myhmacsha1.ComputeHash(stream);
string k = Convert.ToBase64String(Encoding.ASCII.GetBytes(hashValue.ToString()));
console.WriteLine(Expire);
console.WriteLine(k);
I Got OutPut
1357039353
U3lzdGVtLkJ5dGVbXQ==