Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

hash_pbkdf2

Description

The hash_pbkdf2 of Hash for PHP generate a PBKDF2 key derivation of a supplied password.

Syntax

hash_pbkdf2(
    string $algo,
    string $password,
    string $salt,
    int $iterations,
    int $length = 0,
    bool $binary = false
): string

Parameters

algo

Name of selected hashing algorithm.

password

The password to use for the derivation.

salt

The salt to use for the derivation. This value should be generated randomly.

iterations

The number of internal iterations to perform for the derivation.

length

The length of the output string. If binary is true this corresponds to the byte-length of the derived key, if binary is false this corresponds to twice the byte-length of the derived key (as every byte of the key is returned as two hexits).

If 0 is passed, the entire output of the supplied algorithm is used.

binary

When set to true, outputs raw binary data. false outputs lowercase hexits.

Return

Returns a string containing the derived key as lowercase hexits unless binary is set to true in which case the raw binary representation of the derived key is returned.

Examples

1 · algo password salt iterations

<?

$algo = 'sha384';
$password = 'password';
$salt = random_bytes(16);
$iterations = 1000;

$return = hash_pbkdf2($algo, $password, $salt, $iterations);

echo $return;

?>
83806c25a5fcf85ea803228d31f35dda9feae0b6f4319817252e7336913450c54215839dc38cb96db888b2f1a99b6c3e

2 · length

<?

$algo = 'sha384';
$password = 'password';
$salt = random_bytes(16);
$iterations = 1000;
$length = 32;

$return = hash_pbkdf2($algo, $password, $salt, $iterations, $length);

echo $return;

?>
d05e69d78157cef44c651d4a2ccf8134

3 · binary

<?

$algo = 'sha384';
$password = 'password';
$salt = random_bytes(16);
$iterations = 1000;
$length = 32;
$binary = true;

$return = hash_pbkdf2($algo, $password, $salt, $iterations, $length, $binary);

echo $return . PHP_EOL . bin2hex($return);

?>
[(/o���?�7 B���H�n{M���]x��D�
5b282f6f9bb8ad3ff3371d20428e82e348e0a16e7b4dff07b58a5d78ccce44a0
HomeMenu