Derive cryptographically strong keys from raw input using HKDF.
Both PBKDF2 and HKDF are Key Derivation Functions (KDFs). They both take some input material and output a cryptographic key. However, they solve two entirely different problems.
HKDF operates in two distinct mathematical phases:
Because of its speed and mathematical properties, HKDF is a core component of modern secure protocols:
When calling the Expand phase, the Info parameter is technically optional, but omitting it is a serious architectural failure in complex protocols.
The Info string ensures context separation. If two different subsystems (e.g., encryption and MAC generation) both request a key from the same master secret without providing a unique Info string, they will receive the exact same key. This violates cryptographic isolation principles.
Which Key Derivation Function should you use when hashing a user's password for storage in a database?