hash_hkdf
Description
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); ?>
h9�t{�K��Q��#��ED���r��>��y+Yu;f�9_���/U7 680739b7747ba94bdfe651f9af23dce3854544b60eb3c772c1983ea7c0792b59753b66051fd6395f03851c92a42f5537
2 · length
<? $algo = 'sha384'; $key = random_bytes(32); $length = 32; $return = hash_hkdf($algo, $key, $length); echo $return . PHP_EOL . bin2hex($return); ?>
�0�)��Fvl�R� �B:���˰�tȪ�/� a330ef29a0a60246766cff52fa0aa6427f7f063abebd86cbb09774c8aa9f2fc7
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); ?>
xJsL��]ղ�d�.EB�Y{��D���A^���ș 784a734c8fdc5dd5b2f864fb2e4542c0597bfd8f44ded4d9415ea6e194e0c899
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); ?>
�g�g����I{+T©���k#�&�b�e�� b367b267a0afb20fc6490e037b2b54c2a98b19fa07c76b23be26b262cc65f6f0