HKDF implementations in Java
No, the hashed message key derivation function (HMAC) (HKDF) , like most KDFs, does not have a standard implementation in the JCA.
There are several implementations implemented in other projects (for example, you already said):
, , Bouncy Castle, Hmac/Mac API. BC, , , . . , java lib ( RFC 5869), javax.crypto.Mac :
, , , , JCA Hmac.
HKDF
RFC 5869:
"info" HKDF, . - . (...) , .
, , IV , ( lib):
String userInput = "this is a user input with bad entropy";
HKDF hkdf = HKDF.fromHmacSha256();
byte[] pseudoRandomKey = hkdf.extract(staticSalt32Byte, userInput.getBytes(StandardCharsets.UTF_8));
byte[] expandedAesKey = hkdf.expand(pseudoRandomKey, "aes-key".getBytes(StandardCharsets.UTF_8), 16);
byte[] expandedIv = hkdf.expand(pseudoRandomKey, "aes-iv".getBytes(StandardCharsets.UTF_8), 16);
SecretKey key = new SecretKeySpec(expandedAesKey, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(expandedIv));
byte[] encrypted = cipher.doFinal("my secret message".getBytes(StandardCharsets.UTF_8));