PBKDF2 with HMAC (with SHA-1, SHA-256, SHA-384 or SHA-512) as the PRF function for Node.js and browsers.
Node version internally uses Node's crypto.pbkdf2()
, the browser version defaults to the subtle crypto native implementation, although a custom implementation is provided just in case the native one fails. This is nowadays (Jun, 2020) the case of Firefox, whose PBKDF2 implementation can't derive more than 2048 bits.
pbkdf2-hmac
can be imported to your project with npm
:
npm install pbkdf2-hmac
Then either require (Node.js CJS):
const pbkdf2Hmac = require('pbkdf2-hmac')
or import (JavaScript ES module):
import pbkdf2Hmac from 'pbkdf2-hmac'
The appropriate version for browser or node is automatically exported.
You can also download the IIFE bundle, the ESM bundle or the UMD bundle and manually add it to your project, or, if you have already installed pbkdf2-hmac
in your project, just get the bundles from node_modules/pbkdf2-hmac/dist/bundles/
.
An example of usage could be:
const derivedKey = await pbkdf2Hmac('password', 'salt', 1000, 32)
See the test
for more examples.