Skip to content

Instantly share code, notes, and snippets.

@mattmahn
Created April 20, 2017 23:48
Show Gist options
  • Save mattmahn/6edac174b0e7ab85b5cba5461cc67673 to your computer and use it in GitHub Desktop.
Save mattmahn/6edac174b0e7ab85b5cba5461cc67673 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const crypto = require('crypto');
const NUM = 3e5;
function SnH(password, salt) {
return new Promise((resolve) => {
let originalSalt = salt;
password = Buffer.from(password);
salt = Buffer.from(salt);
console.time('hashinate');
let hash = crypto.createHash('sha256').update(Buffer.concat([password, salt])).digest('hex');
for (let i = 0; i < NUM; i++) {
hash = crypto.createHash('sha256').update(Buffer.concat([salt, Buffer.from(hash, 'hex')])).digest('hex');
// hash = algo.update(Buffer.concat([salt, Buffer.from(hash.digest('hex'))]));
}
console.timeEnd('hashinate');
resolve({
hash,
salt: originalSalt
});
});
}
SnH('password', 'what about the BaBIES?!?!?').then(({ salt, hash }) => {
console.log(`salt: ${salt}`);
console.log(`hash: ${hash}`);
}).catch(err => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment