【发布时间】:2019-09-09 10:28:34
【问题描述】:
我在php中有这两个函数。
public function hashSSHA($password) {
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted_password = base64_encode(sha1($password . $salt, true).$salt);
$hash = array("salt"=>$salt, "encrypted"=>$encrypted_password);
return $hash;
}
//Password Decryption
public function checkhashSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true).$salt);
return $hash;
}
我正在尝试在 node js 中编写这两个函数。
这是我尝试过的。
const hash = crypto.createHash('sha1', 'my different salt from DB');
hash.update(password);
console.log(hash.digest('base64'));
但它们都产生了不同的结果。
【问题讨论】:
-
你做不同的事情。首先,一定要使用相同的
salt和password。然后在您的 php 代码中,在计算结果时使用两次salt。这当然会导致不同的结果