Static
deriveDerives a cryptographic key from a password using the PBKDF2 algorithm.
The parameters for key derivation.
A Promise that resolves to the derived key as a Uint8Array.
This method applies the PBKDF2 algorithm to the provided password along with a salt value and iterates the process a specified number of times. It uses a cryptographic hash function to enhance security and produce a key of the desired length. The method is capable of utilizing either the Web Crypto API or the Node.js Crypto module, depending on the environment's support.
const derivedKey = await Pbkdf2.deriveKey({
hash: 'SHA-256',
password: new TextEncoder().encode('password'),
salt: new Uint8Array([...]),
iterations: 1000,
length: 256
});
The
Pbkdf2
class provides a secure way to derive cryptographic keys from a password using the PBKDF2 (Password-Based Key Derivation Function 2) algorithm.The PBKDF2 algorithm is widely used for generating keys from passwords, as it applies a pseudorandom function to the input password along with a salt value and iterates the process multiple times to increase the key's resistance to brute-force attacks.
This class offers a single static method
deriveKey
to perform key derivation.Example
Remarks
This class relies on the availability of the Web Crypto API.