我正在使用此函数为密码生成哈希,然后将其存储在数据库 (SQL Server) 中。
代码如下所示:
byte[] saltBytes = new byte[16];
new RNGCryptoServiceProvider ().GetBytes (saltBytes);
string salt = Convert.ToBase64String (saltBytes);
string saltedPasswordHash =
FormsAuthentication.HashPasswordForStoringInConfigFile (password + salt, FormsAuthPasswordFormat.SHA1.ToString ());
现在的问题是:HashPasswordForStoringInConfigFile () 的输出格式是什么 - 我是将其存储为 char(length) 还是 nchar(length)?
或者是否有任何其他首选方式来存储散列,也许不是字符串?
非常感谢任何输入和半相关的评论。
最佳答案
SQL Server 支持旨在存储二进制数据的二进制列(binary(len)
和varbinary(len)
)。您可能要考虑使用它们。在这种情况下,您可以直接使用 System.Security.Cryptography.SHA512Managed
等类,而不是 HashPasswordForStoringInConfigFile
关于c# - HashPasswordForStoringInConfigFile()的输出是什么格式,如何存储最好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/740584/