javascript - PHP And Node.JS - Crypto PBKDF2 -
i trying node.js crypto pbkdf2 match same value php crypto pbkdf2. reason, not same.
in javascript
const crypto = require('crypto'); crypto.pbkdf2('secret', 'salt', 100000, 20, 'sha512', (err, key) => { console.log(key.tostring()); });
output: 7e������]�9��j]�i
in php
$password = "secret"; $iterations = 100000; $salt = "salt"; $hash = hash_pbkdf2("sha512", $password, $salt, $iterations, 20); echo $hash;
output: 3745e482c6e0ade35da1
why js output not matching php?
you can use option raw_output of hash_pbkdf2 method in php , compare base64
in php
<?php $password = "secret"; $iterations = 100000; $salt = "salt"; $hash = hash_pbkdf2("sha512", $password, $salt, $iterations, 20, true); echo base64_encode($hash); ?>
in nodejs
const crypto = require('crypto'); crypto.pbkdf2('secret', 'salt', 100000, 20, 'sha512', (err, key) => { console.log(new buffer(key).tostring('base64')); });
Comments
Post a Comment