Example 1 — Derive a 32-Byte Key
Turn a master key into a new key, then print it as hex.
<?php
$key = hash_hkdf('sha256', 'master-secret', 32, 'encryption', 'salt-123');
echo bin2hex($key), PHP_EOL; How It Works
- Pass the master key. It should be strong and random.
- Ask for 32 bytes. That suits a 256-bit key.
- Add info and salt. They shape the result.
- Convert with `bin2hex()`. The raw bytes become 64 hex digits.

