Fonctions de dérivation de clés
Dérivez des clés cryptographiques en utilisant l'API KDF standard.
Comparaison de Code
✕ Java 8
SecretKeyFactory factory =
SecretKeyFactory.getInstance(
"PBKDF2WithHmacSHA256");
KeySpec spec = new PBEKeySpec(
password, salt, 10000, 256);
SecretKey key =
factory.generateSecret(spec);
✓ Java 25
var kdf = KDF.getInstance("HKDF-SHA256");
SecretKey key = kdf.deriveKey(
"AES",
KDF.HKDFParameterSpec
.ofExtract()
.addIKM(inputKey)
.addSalt(salt)
.thenExpand(info, 32)
.build()
);
Un problème avec ce code ? Dites-le nous.
Pourquoi la méthode moderne gagne
API propre
Pattern builder au lieu de constructeurs encombrants de KeySpec.
Support HKDF
Algorithme HKDF moderne aux côtés de PBKDF2.
Standard
API unifiée pour tous les algorithmes de dérivation de clés.
Ancienne Approche
PBKDF2 manuel
Approche Moderne
API KDF
Depuis JDK
25
Difficulté
Avancé
Support JDK
Fonctions de dérivation de clés
Disponible
Finalisé dans JDK 25 LTS (JEP 510, sept. 2025).
Comment ça fonctionne
L'API KDF fournit une interface standard pour les fonctions de dérivation de clés, y compris HKDF. Elle remplace l'encombrant pattern SecretKeyFactory + PBEKeySpec par une API propre basée sur un builder.
Documentation Associée