I'm trying to re-create Symfony's MessageDigestPasswordEncoder
in the browser.
I have some issue with browserify and crypto module. I try to generate hash with JavaScript but without Node.
Here is my code with node:
var crypto = require('crypto');
var encodePassword = function (raw, salt) {
var salted = raw + '{'+salt+'}',
hash = crypto.createHash('sha512').update(salted, 'utf-8');
for (var i = 1; i < 5000 ; i++) {
hash = crypto.createHash('sha512').update(hash.digest('binary')+salted);
}
return hash.digest('base64');
};
console.log(encodePassword("admin", "81b6zjhf64w8kogsgkgw804ss8gc0w0"));
It returns:
qmNs3bqtTeoS4uRq2Chh1fUNPu+lzn3KR7mWFHAq5NEPrK0QZ9XkLDUniZ39uosnozNrPL7mByzUZ/A19Io4sQ==
Now, considering I need to implement this without node, I used browserify
browserify index.js > crypto.js
I created a test page and include:
<script src="crypto.js"></script>
The console log output is:
JtDIZwGDybG6tG7PE2SeXS0BEa4vOoxpu3y7Il6P6OQL9djmrk5S0vjTGoQowGO22OvQ58tC05eZBt/yvyJv+A==
Any idea about why I have two different results?
Otherwise, is there a way to obtains the same result in pure JS (without node)?