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

hash_hkdf

Description

The hash_hkdf of Hash for PHP 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);

?>
rOǎ�����,�SM&�ݾ�ZK�~u�e�e�N��Y��x:�J�
721a4fc78ee0cb1ccf1aecebfc2c8753194d162600f08bddbeb05a4bfb7e759265e4b865ff4ea2f959b7ed783ae54ad5

2 · length

<?

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

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

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

?>
w����#�������$%s��7̟���˝��
77b4d30fa098238a9b97bd891b87ac242573a1bb37cc9fcc0204ccebcb9db5da

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

?>
36ʓ�bq,~�Y�R�w��DUc�G��4`�1��n]
3336ca93b662712c7eca59f852a577cfde445563e547adae3460c031fae36e5d

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

?>
��~i��5o���>G,'
ye��D�l��
d9f4c0057e69a1c6356fd7cc02e83e47072c270b0d117965c5c944e21a6c91d8
HomeMenu