Created
June 29, 2020 02:45
-
-
Save kosinix/83f31ced9ec289b5855c51af09ba2495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generates random string and password hashing | |
* @type {module:crypto} | |
*/ | |
//// Core modules | |
const crypto = require('crypto'); | |
const util = require('util'); | |
//// External modules | |
//// Modules | |
let randomBytesAsync = util.promisify(crypto.randomBytes); | |
module.exports = { | |
randomStringAsync: async (length = 32) => { | |
let bytes = await randomBytesAsync(length / 2); | |
return bytes.toString('hex'); | |
}, | |
randomString: (length = 32) => { | |
let bytes = crypto.randomBytes(length / 2); | |
return bytes.toString('hex'); | |
}, | |
hashPassword: (password, salt) => { | |
return crypto.pbkdf2Sync(password, salt, 10000, 64, 'sha512').toString('hex'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment