繁体   English   中英

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

[英]Why C# sha512 hash value is different with PHP crypt method?

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

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

C# :

HMACSHA512 hmac = new 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

最后我找到了一个带库的方法: 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM