Why isn't my PHP SHA256 hash equivalent to C# SHA256Managed hash

后端 未结 6 2012
灰色年华
灰色年华 2020-12-20 12:14

Why aren\'t these the same?

php:

    $hash = hash(\'sha256\', $userData[\'salt\'] . hash(\'sha256\', $password) );

c#



        
6条回答
  •  有刺的猬
    2020-12-20 12:35

    C#

    string toHash = "abcdefg"; 
    SHA256Managed hash = new SHA256Managed(); 
    byte[] signatureData = hash.ComputeHash(new UnicodeEncoding().GetBytes(toHash)); 
    string hashResult = System.Convert.ToBase64String(signatureData); 
    

    PHP

    print base64_encode(hash("sha256",mb_convert_encoding("abcdefg","UTF-16LE"),true));
    

    Works for me.

提交回复
热议问题