public class HKDF extends Object implements DerivationAlgorithm<HKDFParams>
The HKDF algorithm is defined as follows:
N = ceil(L/HashLen) T = T(1) | T(2) | T(3) | ... | T(N) OKM = first L bytes of T where: T(0) = empty string (zero length) T(1) = HMAC-Hash(PRK, T(0) | info | 0x01) T(2) = HMAC-Hash(PRK, T(1) | info | 0x02) T(3) = HMAC-Hash(PRK, T(2) | info | 0x03) ...
| Constructor and Description |
|---|
HKDF() |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
deriveKey(byte[] secret,
HKDFParams params)
Derive a key using the HMAC-based Extract-and-Expand Key Derivation Function (HKDF)
as defined in RFC 5869.
|
byte[] |
expandKey(String jceHmacAlgorithmName,
byte[] prk,
byte[] info,
long keyLength)
The method inits Hash-MAC with given PRK (as salt) and output OKM is calculated as follows:
T(0) = empty string (zero length)
T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)
...
|
byte[] |
extractKey(String jceAlgorithmName,
byte[] salt,
byte[] secret)
The method "extracts" the pseudo-random key (PRK) based on HMAC-Hash function
(optional) salt value (a non-secret random value) and the shared secret/input
keying material (IKM).
|
public byte[] deriveKey(byte[] secret,
HKDFParams params)
throws XMLSecurityException
deriveKey in interface DerivationAlgorithm<HKDFParams>secret - The "shared" secret to use for key derivationparams - The key derivation parameters (salt, info, key length, ...)IllegalArgumentException - if the parameters are missingXMLSecurityException - if the hmac hash algorithm is not supportedpublic byte[] extractKey(String jceAlgorithmName, byte[] salt, byte[] secret) throws XMLSecurityException
PRK = HMAC-Hash(salt, IKM)
jceAlgorithmName - the java JCE HMAC algorithm name to use for key derivation
(e.g. HmacSHA256, HmacSHA384, HmacSHA512)salt - the optional salt value (a non-secret random value);secret - the shared secret/input keying material (IKM) to use for
key derivationXMLSecurityException - if the jceAlgorithmName is not supportedpublic byte[] expandKey(String jceHmacAlgorithmName, byte[] prk, byte[] info, long keyLength) throws XMLSecurityException
T(0) = empty string (zero length) T(1) = HMAC-Hash(PRK, T(0) | info | 0x01) T(2) = HMAC-Hash(PRK, T(1) | info | 0x02) T(3) = HMAC-Hash(PRK, T(2) | info | 0x03) ...
jceHmacAlgorithmName - the java JCE HMAC algorithm name to use to expand
the key (e.g. HmacSHA256, HmacSHA384, HmacSHA512)prk - pseudo-random key derived from the shared secretinfo - used to derive the keykeyLength - key length in bytes of the derived keyXMLSecurityException - if the jceHmacAlgorithmName is not supportedCopyright © 2000–2025 The Apache Software Foundation. All rights reserved.