【发布时间】:2010-10-12 18:02:15
【问题描述】:
我有几段不同的代码,但简短的故事是我使用 SHA1 将一些密码插入 MySQL 数据库,并将 SHA1 哈希计算到 .NET 中,但它们不匹配。我认为这是我在 .NET 中的编码代码的问题。
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 应用程序中使用此解决方案:stackoverflow.com/questions/17832306/…
标签: c# mysql cryptography sha1 cryptographic-hash-function