我有幾個不同的代碼位,但簡短的故事是我使用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