문제

이것은 내 PHP 코드입니다.

hash_hmac( "sha256", utf8_encode( $filename ), utf8_encode( $password ) );

그리고 이것은 내 C# 코드입니다.

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

불행히도 두 결과 모두 다릅니다. 누구든지 나에게 힌트를 줄 수 있습니까?

도움이 되었습니까?

해결책

내 C#이 최고는 아니지만 작동하게되었습니다. 바이트 배열 결과를 16 진로 변환하는 것입니다.

PHP

$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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top