FIPS 验证算法在数据库中存储密码?
我正在寻找一种经过 FIPS 验证的哈希算法来将密码存储在数据库中。 我确实使用了以下代码,但仍然收到错误
此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。
SHA1CryptoServiceProvider Testsha1 = new SHA1CryptoServiceProvider();
byte[] hashedBytes;
UTF8Encoding encoder = new UTF8Encoding();
hashed = Testsha1.ComputeHash(encoder.GetBytes(strPassword));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashed.Length; i++)
{
sbuilder.Append(hashed[i].ToString("x2"));
}
string Password = sb.ToString();
I am looking for a FIPS validated hash algorithm to store passwords in the database.
I did use the following code but I still get the error
This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms.
SHA1CryptoServiceProvider Testsha1 = new SHA1CryptoServiceProvider();
byte[] hashedBytes;
UTF8Encoding encoder = new UTF8Encoding();
hashed = Testsha1.ComputeHash(encoder.GetBytes(strPassword));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashed.Length; i++)
{
sbuilder.Append(hashed[i].ToString("x2"));
}
string Password = sb.ToString();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不应使用普通 SHA-1 来存储密码。 PBKDF2是一个不错的选择。在 .net 中,您可以将其与 Rfc2898DeriveBytes 类一起使用。请参阅https://security.stackexchange.com /questions/2131/reference-implementation-of-c-password-hashing-and-verification/2136#2136
您可能需要将底层哈希函数更改为SHA-256。据我所知,SHA-1 并未获得 NIST 批准。
Plain SHA-1 should not be used to store passwords. PBKDF2 is a good choice. In .net you can use it with the
Rfc2898DeriveBytes
class. See https://security.stackexchange.com/questions/2131/reference-implementation-of-c-password-hashing-and-verification/2136#2136You might need to change the underlying hash function to SHA-256. From what I remember SHA-1 isn't NIST approved.
在 system.web 部分下的 web.config 中添加以下行
解决了我的问题
Adding the following line in web.config under system.web section
<machineKey validationKey="AutoGenerate,IsolateApps" ecryptionKey="AutoGenerate,IsolateApps" validation="3DES" decryption="3DES"/>
solved my problem
使用 SHA-2 系列中的哈希值之一。例如,SHA256。
不要使用托管类 - 它们未经过 FIPS 验证。相反,请使用 SHA256CryptoServiceProvider 等。
Use one of the hashes from the SHA-2 family. For example, SHA256.
Do not use a managed class - they are not FIPS validated. Instead, use
SHA256CryptoServiceProvider
and friends.