Technically, the input data for PBKDF2 consists of:
password – array of bytes / string, e.g. "[email protected]$Sw0rD~3" (8-10 chars minimal length is recommended)
salt – securely-generated random bytes, e.g. "df1f2d3f4d77ac66e9c5a6c3d8f921b6" (minimum 64 bits, 128 bits is recommended)
iterations-count, e.g. 1024 iterations
hash-function for calculating HMAC, e.g. SHA256
derived-key-len for the output, e.g. 32 bytes (256 bits)
The output data is the derived key of requested length (e.g. 256 bits).
PBKDF2 and Number of Iterations
PBKDF2 allows to configure the number of iterations and thus to configure the time required to derive the key.
Slower key derivation means high login time / slower decryption / etc. and higher resistance to password cracking attacks.
Faster key derivation means short login time / faster decryption / etc. and lower resistance to password cracking attacks.
PBKDF2 is not resistant to GPU attacks (parallel password cracking using video cards) and to ASIC attacks (specialized password cracking hardware). This is the main motivation behind more modern KDF functions.
The PBKDF2 calculation function takes several input parameters: hash function for the HMAC, the password (bytes sequence), the salt (bytes sequence), iterations count and the output key length (number of bytes for the derived key).
The output from the above code execution is the following:
Try to change the number of iterations and see whether and how the execution time changes.
When to Use PBKDF2?
Today PBKDF2 is considered old-fashioned and less secure than modern KDF functions, so it is recommended to use Bcrypt, Scrypt or Argon2 instead. We shall explain all these KDF functions in details later in this section.