为什么C#sha512哈希值与PHP crypt方法不同?

时间:2019-04-28 09:58:29

标签: c# php crypt sha512

我使用相同的盐和密码,但是C#和PHP中的哈希值不同。为什么会这样?

string password = "password";
string salt = "salt";

C#:

HMACSHA512 hmac =新的HMACSHA512(Encoding.UTF8.GetBytes(salt));

        byte[] bithash = Encoding.UTF8.GetBytes(password);

        for (int i = 0; i < 7778;i++){
            bithash = hmac.ComputeHash(bithash);
        }

        Console.WriteLine( Convert.ToBase64String(bithash) );

uQobtR+v8PovsSOjCZ9tZyOsfUYWw+xZSOMEuljCzXdezVs8LiM85I1JRQsVpKGSalrC5xTu5sU2f127Bw3DoA==

PHP:

crypt('password','$6$rounds=7778$salt$'); 

QVysRURDsOGt7/ig9jE7JNutVD2XWO5h9gmBmvC5HtEUFUtVNugF3GWJe6CwFkVNq91kJY8yL5QVPQYXUzhoM1

1 个答案:

答案 0 :(得分:0)

最后我找到了一个带有库的方法:https://www.zer7.com/software.php?page=cryptsharp


string password = "password";
string salt = "$6$rounds=7777$salt";

CryptSharp.Sha512Crypter sha512Crypter = new Sha512Crypter();

var hash = sha512Crypter.Crypt(password, salt);
Console.WriteLine(hash);
Console.ReadLine();