I would like to convert this piece of node.js code to PHP code. (WORKING)
function generateHashedPass (password, salt) { var byteSalt = new Buffer(salt, 'base64'); var bytePass = new Buffer(password, 'ucs2'); var byteResult = Buffer.concat([byteSalt, bytePass]); return sha1.update(byteResult).digest('base64'); } console.log(generateHashedPass('111111', 'UY68RQZT14QPgSsfaw/F+w==') === 'L0xc787MxCwJJaZjFX6MqxkVcFE=' ? "Algo correct" : "Algo wrong" );
Now I have something similar in php: (DOES NOT WORK)
public function getHashedPass($pass, $salt) { $base_salt = unpack('H*', base64_decode($salt)); $base_pass = unpack('H*', mb_convert_encoding($pass, 'UCS-2', 'auto')); $base_result = $base_salt[1] . $base_pass[1]; return base64_encode(sha1($base_result)); }
But the result does not match the node.js. function
The result should be as follows: L0xc787MxCwJJaZjFX6MqxkVcFE =
When is the password: 111111
And there is salt: UY68RQZT14QPgSsfaw / F + w ==
source share