module

Beryl::Crypto::Compatibility::PasswordBasedKeyDerivationFunction2(D)

PBKDF2 with HMAC (RFC 8018 ยง5.2): stretches a password into a key by repeating HMAC iteration_count times. D is SHA1, V1::SHA256 or V1::SHA512.

NOTE: PBKDF2 is here for formats that require it, such as PostgreSQL SCRAM-SHA-256 (RFC 7677). It is not the password hash to choose for a new design.

pbkdf2 = Beryl::Crypto::Compatibility::PBKDF2(Beryl::Crypto::V1::SHA256)
salted_password = pbkdf2.derive_key("pencil", salt: salt, iteration_count: 4096, bytesize: 32)

Class methods

derive_key(password : Bytes | String, *, salt : Bytes | String, iteration_count : Int32, bytesize : Int32) : Bytes

Returns bytesize bytes of key derived from password and salt.

Raises IterationCountTooSmall when iteration_count is under one and DerivedKeySizeIsNegative when bytesize is negative.

Source