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;

?>
78fa0405484dd17108ba57a1905ad42717d0107ade052e90ab3aab4309c050d1a3bc9499cc17b4ee51d818365ac5b6c7

2 · length

<?

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

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

echo $return;

?>
fb98ed76e6eb787308857a280c0cac52

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);

?>
S�&
�_5o�F*�~��3�'(C��|��5Eg�
5384260ae15f356fb3462aa7177ed9df33df272843a7f19a7cbcc906354567e0
HomeMenu