<img src="https://img.shields.io/npm/v/@kdf/salt.svg" alt="Latest version on npm" />
<img src="https://img.shields.io/npm/dt/@kdf/salt.svg" alt="Downloads on npm" />
<img src="https://img.shields.io/github/license/simonepri/node-kdf.svg" alt="Project license" />
<img src="https://github.com/simonepri/node-kdf/workflows/salt-lint/badge.svg?branch=master" alt="Lint status" />
<img src="https://github.com/simonepri/node-kdf/workflows/salt-test-macos/badge.svg?branch=master" alt="Test macOS status" />
<img src="https://github.com/simonepri/node-kdf/workflows/salt-test-ubuntu/badge.svg?branch=master" alt="Test Ubuntu status" />
<img src="https://github.com/simonepri/node-kdf/workflows/salt-test-windows/badge.svg?branch=master" alt="Test Windows status" />
<img src="https://codecov.io/gh/simonepri/node-kdf/branch/master/graph/badge.svg?flag=salt" alt="Codecov Coverage report" />
<img src="https://snyk.io/test/github/simonepri/node-kdf/badge.svg?targetFile=packages/salt/package.json" alt="Known Vulnerabilities" />
<img src="https://david-dm.org/simonepri/node-kdf/status.svg?path=packages/salt" alt="Dependency Status" />
<img src="https://img.shields.io/badge/code_style-XO+Prettier-5ed9c7.svg" alt="XO Code Style used" />
<img src="https://img.shields.io/badge/test_runner-AVA-fb3170.svg" alt="AVA Test Runner used" />
<img src="https://img.shields.io/badge/test_coverage-NYC-fec606.svg" alt="Istanbul Test Coverage used" />
<img src="https://img.shields.io/badge/initialized_with-ni-e74c3c.svg" alt="NI Scaffolding System used" />
<img src="https://img.shields.io/badge/released_with-np-6c8784.svg" alt="NP Release System used" />
🎲 Crypto secure salt generator
Coded with ❤️ by <a href="#authors">Simone Primarosa</a>.
Install
npm install --save @kdf/salt
Usage
const gensalt = require('@kdf/salt');
gensalt(16).then(salt => {
console.log(salt);
// => <Buffer 70 2c 6e 1c c1 07 2e 26 dc 82 52 4e 1b cf 1d 23>
console.log(salt.toString('base64'));
// => cCxuHMEHLibcglJOG88dIw==
console.log(salt.toString('hex'));
// => 702c6e1cc1072e26dc82524e1bcf1d23
})
API
gensalt(length) ⇒ Promise.<Buffer>
Generates a cryptographically secure random string to be used as a password salt
, using Node's built-in crypto.randomBytes() function.Kind: global function
Returns:
Promise.<Buffer>
- The salt as a Buffer.Access: public
| Param | Type | Description | | --- | --- | --- | | length |
number
| The length of the salt to be generated. Must be an integer within the range (0
<= length
<= 2^31-1
). |Contributing
Contributions are REALLY welcome and if you find a security flaw in this code, PLEASE report itnew issue.Authors
- Simone Primarosa - Github (@simoneprigithub:simonepri) • Twitter (@simoneprimarosatwitter:simoneprimarosa)
See also the list of contributorscontributors who participated in this project.