cleaker
Version:
Connecting all dots within a fixed distance.
21 lines (18 loc) • 518 B
JavaScript
//cleaker/src/methods/salt.js
import crypto from 'crypto';
/**
* Generates a cryptographic salt for password hashing.
*
* @param {number} [length=16] - The desired length of the salt in bytes.
* @returns {string} A randomly generated salt in hexadecimal format.
*
* @example
* import salt from './salt.js';
*
* const mySalt = salt(16);
* console.log(mySalt); // Example output: 'e3b0c44298fc1c14'
*/
function salt(length = 16) {
return crypto.randomBytes(length).toString('hex');
}
export default salt;