我试图在HMACSHA1和C#中使用C#进行加密,但结果不同。C#部分完成。我想让part生成与C#部件相同的结果。
C#
string key = "x94IudsnSUWCDSiSxRU5qDSRs88=";
string text = "The quick brown fox jumps over the lazy dog";
HMACSHA1 hmac = new HMACSHA1();
hmac.Key = Convert.FromBase64String(key);
byte[] hashedData = hmac.ComputeHash(Encoding.UTF8.GetBytes(text));
string hash = Convert.ToBase64String(hashedData, Base64FormattingOptions.None);
Console.WriteLine(WebUtility.UrlEncode(hash));PHP
$key = "x94IudsnSUWCDSiSxRU5qDSRs88=";
$text = "The quick brown fox jumps over the lazy dog";
$hash = base64_encode(hash_hmac('sha1', $text, $key,true));
echo urlencode($hash);结果: C#:uAG0CDzyuEq7zbQ5ZfpVrb1ZUcA%3D PHP:hx2c5SS6xI%2B8hQBoUqsWQT4KwP4%3D
发布于 2015-12-05 23:11:26
在将密钥传递给hash_hmac函数之前,您可能必须先将php中的密钥传递给它。
https://stackoverflow.com/questions/34111988
复制相似问题