hash_hkdf
hash_hkdf
Generate a HKDF key derivation of a supplied key input
string **hash_hkdf** string $algo string $key int $length string $info string $salt
algo
Name of selected hashing algorithm (e.g. ).
For a list of supported algorithms see .
`"sha256"``hash_hmac_algos`> **Opmerking:** > Non-cryptographic hash functions are not allowed.
keyInput keying material (raw binary). Cannot be empty.
lengthDesired output length in bytes.
Cannot be greater than 255 times the chosen hash function size.
If is , the output length
will default to the chosen hash function size.
`length``0`
infoApplication/context-specific info string.
saltSalt to use during derivation.
While optional, adding random salt significantly improves the strength of HKDF.
Returns a string containing a raw binary representation of the derived key (also known as output keying material - OKM).
Throws a exception if
is empty, is unknown/non-cryptographic,
is less than or too large
(greater than 255 times the size of the hash function).
ValueError``key``algo``length``0
The example below produces a pair of separate keys, suitable for creation of an encrypt-then-HMAC construct, using AES-256 and SHA-256 for encryption and authentication respectively.
Voorbeeld: example
<?php
// Generate a random key, and salt to strengthen it during derivation.
$inputKey = random_bytes(32);
$salt = random_bytes(16);
// Derive a pair of separate keys, using the same input created above.
$encryptionKey = hash_hkdf('sha256', $inputKey, 32, 'aes-256-encryption', $salt);
$authenticationKey = hash_hkdf('sha256', $inputKey, 32, 'sha-256-authentication', $salt);
var_dump($encryptionKey !== $authenticationKey); // bool(true)
?>
hash_pbkdf2RFC 5869userland implementation