hash_hkdf

Generate a HKDF key derivation of a supplied key input

Syntax

hash_hkdf(
    string $algo,
    string $key,
    int $length = 0,
    string $info = "",
    string $salt = ""
): string

Parameters

algo

Name of selected hashing algorithm.

key

Input keying material (raw binary). Cannot be empty.

length

Desired output length in bytes. Cannot be greater than 255 times the chosen hash function size.

If length is 0, the output length will default to the chosen hash function size.

info

Application/context-specific info string.

salt

Salt to use during derivation.

While optional, adding random salt significantly improves the strength of HKDF.

Return

Returns a string containing a raw binary representation of the derived key (also known as output keying material - OKM).

Examples

1 · algo key

<?

$algo = 'sha384';
$key = random_bytes(32);

$return = hash_hkdf($algo, $key);

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

?>
�� Df�0��DR�C�U�S����4��t��Bg�lO��
f2ba1ff0204466e430bcdc445200a1431dd155f5530816e0b71ceee80fac1634b4af741e0f1418fbb14267ee6c4ffffa

2 · length

<?

$algo = 'sha384';
$key = random_bytes(32);
$length = 32;

$return = hash_hkdf($algo, $key, $length);

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

?>
��n���q�Ѭ���\�>\D��b3
d61c7fe66e8ec1d0120771a6d1ac14bee0e6a40f035ceb3e5c44fbf49bb86233

3 · info

<?

$algo = 'sha384';
$key = random_bytes(32);
$length = 32;
$info = 'sha-384-authentication';

$return = hash_hkdf($algo, $key, $length, $info);

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

?>
����B^��W�۹�˓���S^*���4���
aaf07fb5f8425ebfca57d2dbb9e7cb93a6b0b3531c5e112aa489df34cf0eb88a

4 · salt

<?

$algo = 'sha384';
$key = random_bytes(32);
$length = 32;
$info = 'sha-384-authentication';
$salt = random_bytes(16);

$return = hash_hkdf($algo, $key, $length, $info, $salt);

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

?>
=��>���l��8t2��'�+v��Q�m�d}?E
3d85a73e9ee6f26cfd1ea4387432cbf3279d2b087681b351876d15f9647d3f45
HomeMenu