Module org.apache.santuario.xmlsec
Class HKDF
- java.lang.Object
-
- org.apache.xml.security.encryption.keys.content.derivedKey.HKDF
-
- All Implemented Interfaces:
DerivationAlgorithm<HKDFParams>
public class HKDF extends java.lang.Object implements DerivationAlgorithm<HKDFParams>
The implementation of the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.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) ...
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.System.LoggerLOG
-
Constructor Summary
Constructors Constructor Description HKDF()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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(java.lang.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:byte[]extractKey(java.lang.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).private javax.crypto.MacinitHMac(java.lang.String jceAlgorithmName, byte[] initSecret, boolean initPRK)Method initializes a Message Authentication Code (MAC) object using the init secret/salt or an empty byte array if initSecret parameter is null or empty.
-
-
-
Method Detail
-
deriveKey
public byte[] deriveKey(byte[] secret, HKDFParams params) throws XMLSecurityExceptionDerive a key using the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.- Specified by:
deriveKeyin interfaceDerivationAlgorithm<HKDFParams>- Parameters:
secret- The "shared" secret to use for key derivationparams- The key derivation parameters (salt, info, key length, ...)- Returns:
- The derived key of the specified length in bytes defined in the params
- Throws:
java.lang.IllegalArgumentException- if the parameters are missingXMLSecurityException- if the hmac hash algorithm is not supported
-
extractKey
public byte[] extractKey(java.lang.String jceAlgorithmName, byte[] salt, byte[] secret) throws XMLSecurityExceptionThe 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). Calculation of the extracted key:PRK = HMAC-Hash(salt, IKM)
- Parameters:
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 derivation- Returns:
- the pseudo-random key bytes
- Throws:
XMLSecurityException- if the jceAlgorithmName is not supported
-
expandKey
public byte[] expandKey(java.lang.String jceHmacAlgorithmName, byte[] prk, byte[] info, long keyLength) throws XMLSecurityExceptionThe 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) ...
- Parameters:
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 key- Returns:
- the output keying material (OKM) size of keyLength octets
- Throws:
XMLSecurityException- if the jceHmacAlgorithmName is not supported
-
initHMac
private javax.crypto.Mac initHMac(java.lang.String jceAlgorithmName, byte[] initSecret, boolean initPRK) throws XMLSecurityExceptionMethod initializes a Message Authentication Code (MAC) object using the init secret/salt or an empty byte array if initSecret parameter is null or empty.- Parameters:
jceAlgorithmName- the java JCE HMAC algorithm name to use to init MacinitSecret- the secret/salt to initialize the hmacinitPRK- if true, the salt is initialized with a string of zero octets as long as the hash function output see [RFC5869] Section 2.2- Returns:
- Initialized Mac object
- Throws:
XMLSecurityException- if the hmac algorithm is not supported or if it fails to initialize
-
-