/** * Hi() is, essentially, PBKDF2 [RFC2898] with HMAC() as the * pseudorandom function (PRF) and with dkLen == output length of * HMAC() == output length of H() * * @returns {Promise<Buffer>} */ static hi(password, salt, iterations, digestDefinition) { return new Promise((resolve, reject) => { crypto.pbkdf2( password, salt, iterations, digestDefinition.length, digestDefinition.type, (err, derivedKey) => (err ? reject(err) : resolve(derivedKey)) ) }) }
crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, function (err, key) { if (err) { callback(err); } return callback(null, key.toString('base64')); })
app.get("*", (req, res) => { //doWork(5000); const start = Date.now(); crypto.pbkdf2("a", "b", 100000, 512, "sha512", () => { const msg = "1:" + (Date.now() - start); console.log("Send " , msg); res.status(200).send(msg); }); });
crypto.randomBytes(len, function(err, salt) { if (err) return fn(err); salt = salt.toString('base64'); crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash) { if (err) return fn(err); fn(null, salt, hash.toString('base64')); }); });
function doHash() { crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { console.log('Hash:', Date.now() - start); }); }
app.get('/slow', (req, res) => { crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { res.send('Hello World, This was slow!'); }); });
function doWorkReal(cb) { crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { cb() }) }
crypto.randomBytes(len, function(err, salt) { if (err) return fn(err); salt = salt.toString('base64'); crypto.pbkdf2(pwd, salt, iterations, len, function(err, hash) { if (err) return fn(err); fn(null, salt, hash); }); });
app.get("*", (req, res) => { //doWork(5000); const start = Date.now(); crypto.pbkdf2("a", "b", 100000, 512, "sha512", () => { const msg = "1:" + (Date.now() - start); console.log("Send " , msg); res.status(200).send(msg); }); });
app.get('/slow', (req, res) => { crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { res.send('Hello World, This was slow!'); }); });
// I am a child, i am going to act like a server app.get('/', (req, res) => { crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { res.send('Hello World'); }); });
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { console.log('4:', Date.now() - start); });
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { console.log('1:', Date.now() - start); });
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { console.log('2:', Date.now() - start); });
crypto.pbkdf2('a', 'b', 100000, 512, 'sha512', () => { console.log('3:', Date.now() - start); });