【发布时间】:2014-01-22 10:32:12
【问题描述】:
我正在使用 bcrypt 对我的密码进行哈希处理(实际上是使用 password_compat,因为我运行的是 php 5.3.10)
我想将函数的结果字符串分成两部分:使用的盐和哈希本身。 (我知道使用 password_verify() 来验证密码。但我需要哈希值才能将其用作密钥,以便在更广泛的安全系统中加密私钥。)
对于给定的密码 (abcdef),结果如下:
$2y$10$ult68Ti4/zEWX4VQ .... YCOWjL6
我稍微修改了the function,以输出 concat、salt、hash 和 hash_format。
... from the password_compat ...
$salt = substr($salt, 0, $required_salt_len);
$hash = $hash_format . $salt;
$ret = crypt($password, $hash);
if (!is_string($ret) || strlen($ret) <= 13) {
return false;
}
return array( 'concat'=>$ret,
'salt'=>$salt,
'format'=>$hash_format,
'hash_format'=>$hash);
我认为结果哈希是$hash_format、$salt 和hash 的连接...但最后一个字符不同...
_
[concat] => $2y$10$oWfFYcNqlcUeGwJM0AFUguSJ5t ..... SvWG
[salt] => oWfFYcNqlcUeGwJM0AFUgw
[hash_format] => $2y$10$oWfFYcNqlcUeGwJM0AFUgw
[format] => $2y$10$
^
如您所见,盐中的最后一个字符在 crypt 函数之前和函数之后是不同的。
这怎么可能?
【问题讨论】:
-
你为什么要滥用密码哈希库?
-
也许更适合的库是github.com/ircmaxell/RandomLib
-
好吧,我没有滥用它...但是在更广泛的密码派生加密方案中使用它:security.stackexchange.com/a/48085/36643
-
@stUrb:那为什么不使用像 PBKDF2 这样的密钥派生函数 (KDF) 呢?一种专门为从密码生成加密密钥而设计的算法... BCrypt 专为密码存储而设计。 PBKDF2+SHA256|512 将是一个很好的选择...