The PHP hash_hkdf() function returns the hkdf key derivation for the given input key.
HKDF is a key that is derived using HMAC algorithm like md5, sha256, an input key and a salt key.
hash_hkdf ( string $algo , string $ikm [, int $length = 0 [, string $info = '' [, string $salt = '' ]]] ) : string
|Sr.No||Parameter & Description|
Name of the hashing algorithm. There is a big list of algorithm available with hash, some important ones are md5, sha256, etc.
To get the full list of algorithms supported check for hash_hmac_algos()
The length you want in bytes. The length cannot be greater than 255 times the chosen hash function size.
If the length is 0, then the length will be as per the chosen hash function size.
Application/context-specific info string.
The salt secret key is required for derivation. It is optional, but using salt will add strength to HDKF derivation.
<?php $inputKey = random_bytes(32); $salt = 'testingkey'; $HKFD_derivation = hash_hkdf('md5', $inputKey, 32, 'aes-256-encryption', $salt); echo $HKFD_derivation; ?>
<?php $inputKey = random_bytes(32); $salt = 'testingkey'; $HKFD_derivation = hash_hkdf('md5', $inputKey, 0, 'aes-256-encryption', $salt); echo $HKFD_derivation; ?>
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.
Thanks for reading and bye for now.