Skip to content
class method

OpenSSL::KDF.pbkdf2_hmac

(::String pass, salt: ::String, iterations: ::Integer, length: ::Integer, hash: ::String | ::OpenSSL::Digest) -> ::String
KDF.pbkdf2_hmac(pass, salt:, iterations:, length:, hash:) → aString

PKCS #5 PBKDF2 (Password-Based Key Derivation Function 2) in combination with HMAC. Takes pass, salt and iterations, and then derives a key of length bytes.

For more information about PBKDF2, see RFC 2898 Section 5.2 (www.rfc-editor.org/rfc/rfc2898#section-5.2).

Parameters

pass

The password.

salt

The salt. Salts prevent attacks based on dictionaries of common passwords and attacks based on rainbow tables. It is a public value that can be safely stored along with the password (e.g. if the derived value is used for password storage).

iterations

The iteration count. This provides the ability to tune the algorithm. It is better to use the highest count possible for the maximum resistance to brute-force attacks.

length

The desired length of the derived key in octets.

hash

The hash algorithm used with HMAC for the PRF. May be a String representing the algorithm name, or an instance of OpenSSL::Digest.

See also .hkdf .scrypt also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0