crypto.password.pbkdf2

Functions for encrypting passwords using the PBKDF2 algorithm, as recommended by the NIST.

See: http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf

check

(check raw encrypted)

Compare a raw string with a string encrypted with the encrypt function. Returns true if the string matches, false otherwise.

encrypt

(encrypt raw)(encrypt raw iterations)(encrypt raw iterations algorithm)(encrypt raw iterations algorithm salt)

Encrypt a password string using the PBKDF2 algorithm. The default number of iterations is 100,000. If a salt is not specified, 8 random bytes are generated from a cryptographically secure source. The default algorithm is “HMAC-SHA1”. When running on JDK 1.8 “HMAC-SHA256” is also supported.

The number of iterations and salt are encoded in the output in the following formats for HMAC-SHA1:

<iterations>$<salt>$<encrypted password>

And for all other algoritms:

<iterations>$<algorithm>$<salt>$<encrypted password>

The iterations, salt, and encrypted password are all Base64 encoded.