我正在使用C#和BCrypt.Net来散列我的密码。
例如:
string salt = BCrypt.Net.BCrypt.GenerateSalt(6);
var hashedPassword = BCrypt.Net.BCrypt.HashPassword("password", salt);
//This evaluates to True. How? I'm not telling it the salt anywhere, nor
//is it a member of a BCrypt instance because there IS NO BCRYPT INSTANCE.
Console.WriteLine(BCrypt.Net.BCrypt.Verify("password", hashedPassword));
Console.WriteLine(hashedPassword);如果BCrypt没有在任何地方保存盐,它是如何用散列验证密码的。我唯一的想法是,它以某种方式将盐添加到散列的末尾。
这是一个正确的假设吗?
发布于 2011-03-22 23:48:06
如果BCrypt没有将盐保存在任何地方,它如何使用散列验证密码?
显然,它没有做任何这样的事情。盐总得存起来吧。
让我们在维基百科上查找密码加密方案。来自http://en.wikipedia.org/wiki/Crypt_(Unix):
函数的输出不仅仅是散列:它还是一个文本字符串,它还编码salt并标识所使用的散列算法。
或者,您在此主题上的previous question答案中包含source code的链接。源代码的相关部分如下:
StringBuilder rs = new StringBuilder();
rs.Append("$2");
if (minor >= 'a') {
rs.Append(minor);
}
rs.Append('$');
if (rounds < 10) {
rs.Append('0');
}
rs.Append(rounds);
rs.Append('$');
rs.Append(EncodeBase64(saltBytes, saltBytes.Length));
rs.Append(EncodeBase64(hashed,(bf_crypt_ciphertext.Length * 4) - 1));
return rs.ToString();显然,返回的字符串是版本信息,后面是使用的轮数,后面是编码为base64的盐,最后是编码为base64的散列。
https://stackoverflow.com/questions/5393803
复制相似问题