I'm hashing my password with bcrypt (actually with password_compat since I run php 5.3.10)
I wanted to split the result string of the function into two parts: the salt used and the hash itself. (I know to use password_verify() to verify, well, the password. But I need the hash to use it as a key to encrypt a private key in a more broader security system.)
For a given password (abcdef) this is the result:
$2y$10$ult68Ti4/zEWX4VQ .... YCOWjL6
I've altered the function a little bit, to spit out the concat, salt, hash and 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);
I thought the result-hash was a concat of the $hash_format
, $salt
and the hash
... but the last character is different...
_
[concat] => $2y$10$oWfFYcNqlcUeGwJM0AFUguSJ5t ..... SvWG
[salt] => oWfFYcNqlcUeGwJM0AFUgw
[hash_format] => $2y$10$oWfFYcNqlcUeGwJM0AFUgw
[format] => $2y$10$
^
As you can see the last character is different in the salt before the crypt function and after the function.
How is this possible?