add scrypt pbkdf
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-04 21:52:10 +02:00
parent 7d41f8689f
commit 78a535087a
7 changed files with 53 additions and 4 deletions

20
lib/pbkdf.js Normal file
View File

@ -0,0 +1,20 @@
'use strict';
const { scrypt } = require ('scrypt-js');
/**
* creates a scrypt hash
*
* @param {string} str string input
* @param {string} salt salt
* @returns {Promise<string>} hash
*/
async function pbkdf_scrypt (str, salt) {
const bstr = Buffer.from (str.normalize ('NFKC'), 'utf-8');
const bsalt = Buffer.from (salt.normalize ('NFKC'), 'utf-8');
const hash = await scrypt (bstr, bsalt, 65536, 8, 1, 64);
return Buffer.from (hash)
.toString ('hex');
}
module.exports = { pbkdf_scrypt };