我有几个不同的代码位,但简短的故事是我使用SHA1将一些密码插入到MySQL数据库中,并计算到.NET中的SHA1哈希,并且它们不匹配。我认为这是我用.NET编码的问题。.NET和MySQL中SHA1的区别
SQL代码:
INSERT INTO user_credentials (Password) VALUES (SHA1('password'));
密码哈希以5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
.NET代码:??
public static string GetPasswordHash(string password)
{
// problem here with encoding?
byte[] byteArray = Encoding.ASCII.GetBytes(password);
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] hashedPasswordBytes = sha.ComputeHash(byteArray);
return Encoding.ASCII.GetString(hashedPasswordBytes);
}
密码哈希为[A ??????%L 3〜 ???
感谢您的帮助!
我用这解决方案在我的Windows 8应用程序:http://stackoverflow.com/questions/17832306/simulating-mysqls-password-encryption-using-net-in-windows-8/ – Rincha 2013-07-25 09:34:41