Class: PBKDF2

PBKDF2

PBKDF2 class. Derives a symmetric key from a passphrase and optional salt.

new PBKDF2(data)

Creates a new PBKDF2 instance.
This:
Parameters:
Name Type Description
data Object Initialization options for the class, passed automatically into PBKDF2#initialize
Source:
Example
	_kdf		= new PBKDF2({key_size: 16, hasher: SHA256, iterations: 1000});
	derived_key	= _kdf.compute('password1234', 'saltsalt');
	derived_iv	= _kdf.compute(derived_key, 'saltsaltsaltsalt');
	ciphertext	= new AES({key: derived_key, iv: derived_iv}).encrypt('mydata');

	// Note you don't have to do all this work to encrypt using a passphrase.
	// Just initialize your cipher instance using the passphrase option.
	// Doing so will automatically use PBKDF2 internally to generate a key and IV.

Requires

  • module:convert

Methods

compute(passphrase, salt, options) → {string|Array}

Derives a PBKDF2 key from a given passphrase and salt value
Parameters:
Name Type Argument Default Description
passphrase string Passphrase to be used for the derived key.
salt string <optional>
'' Salt value.
options Object <optional>
{} Optional options object.
Properties
Name Type Argument Default Description
return_format string <optional>
'binary' (binary|hex|words) The return format.
Source:
Returns:
A string or Array depending on options.return_format
Type
string | Array

initialize(options) → {PBKDF2}

Initializes the PBKDF2 instance
Parameters:
Name Type Argument Default Description
options Object <optional>
{} Optional options object. (Parameter descriptions below)
Properties
Name Type Argument Default Description
key_size number <optional>
32 The key size to generate. Must be a multiple of 4.
hasher Hasher <optional>
SHA1 The class name of a hasher.
iterations number <optional>
1 Number of iterations to HMAC hash key data.
Source:
Returns:
This initialized instance
Type
PBKDF2