php和c中的hmac#U sha256不同

php和c中的hmac#U sha256不同,c#,php,hashcode,C#,Php,Hashcode,这是我的PHP代码: hash_hmac( "sha256", utf8_encode( $filename ), utf8_encode( $password ) ); 这是我的C代码: 不幸的是,两种结果都不同。有人能给我一个提示吗?我的C#不是最好的,但我让它工作了,你需要做的是将字节数组结果转换为十六进制 PHP $hash = hash_hmac( "sha256", utf8_encode("Filename"), utf8_encode("Password")); echo $h

这是我的PHP代码:

hash_hmac( "sha256", utf8_encode( $filename ), utf8_encode( $password ) );
这是我的C代码:

不幸的是,两种结果都不同。有人能给我一个提示吗?

我的C#不是最好的,但我让它工作了,你需要做的是将字节数组结果转换为十六进制

PHP

$hash = hash_hmac( "sha256", utf8_encode("Filename"), utf8_encode("Password"));
echo $hash;
// 5fe2ae06ff9828b33fe304545289a3f590bfd948ca9ab731c980379992ef41f1
C#


谢谢,我会再检查一遍,今天晚上再回来找你。我已经使用了BitConverter.ToString(hmacsha256.Hash),但是我得到了错误的结果。
$hash = hash_hmac( "sha256", utf8_encode("Filename"), utf8_encode("Password"));
echo $hash;
// 5fe2ae06ff9828b33fe304545289a3f590bfd948ca9ab731c980379992ef41f1
string password = "Password";
string filename = "Filename";

var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(password));
hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(filename));

foreach(byte test in hmacsha256.Hash)
{
    Console.Write(test.ToString("X2"));
}
// 5FE2AE06FF9828B33FE304545289A3F590BFD948CA9AB731C980379992EF41F1