Key Derivation Functions
Derive cryptographic keys using the standard KDF API.
Code Comparison
✕ Java 8
SecretKeyFactory factory =
SecretKeyFactory.getInstance(
"PBKDF2WithHmacSHA256");
KeySpec spec = new PBEKeySpec(
password, salt, 10000, 256);
SecretKey key =
factory.generateSecret(spec);
✓ Java 25
KDF kdf = KDF.getInstance("HKDF-SHA256");
SecretKey key = kdf.deriveKey(
"AES",
KDF.HKDFParameterSpec
.ofExtract()
.addIKM(inputKey)
.addSalt(salt)
.thenExpand(info, 32)
.build()
);
Why the modern way wins
Clean API
Builder pattern instead of awkward KeySpec constructors.
HKDF support
Modern HKDF algorithm alongside PBKDF2.
Standard
Unified API for all key derivation algorithms.
Old Approach
Manual PBKDF2
Modern Approach
KDF API
Since JDK
25
Difficulty
advanced
JDK Support
Key Derivation Functions
Available
Finalized in JDK 25 LTS (JEP 510, Sept 2025).
How it works
The KDF API provides a standard interface for key derivation functions including HKDF. It replaces the awkward SecretKeyFactory + PBEKeySpec pattern with a clean builder API.