Skip to content

Instantly share code, notes, and snippets.

@destinmoulton
Last active February 11, 2020 23:21
Show Gist options
  • Select an option

  • Save destinmoulton/9acc57a82b40906cd1ce929b84b87da9 to your computer and use it in GitHub Desktop.

Select an option

Save destinmoulton/9acc57a82b40906cd1ce929b84b87da9 to your computer and use it in GitHub Desktop.
NodeJS
/**
* Encrypt a Password using PBKDF2
*
* @param {string} password - Plaintext password
* @returns {Promise}
* @resolve {string} The hex value of derived key
* @reject {Error}
*/
function encryptPassword(password) {
return new Promise((resolve, reject) => {
crypto.pbkdf2(
password,
"salt_here", // 64 character long random string
10000,
64, // Output key length in bits
"sha512",
(err, derivedKey) => {
if (err) reject(err);
// Resolve the derived key to hex
resolve(derivedKey.toString("hex"));
}
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment