public class HKDFExpandOnlyParameterSpec
extends java.lang.Object
implements java.security.spec.AlgorithmParameterSpec
HKDF key derivation function.
Generally a HKDF KeyGenerator will be initialized by a HKDFParameterSpec to first extract a pseudorandom key from some input keying
material and then extracts cryptographic strong secret keys from it. However,
if the input already represents a good pseudorandom key (prk), this HKDFExpandOnlyParameterSpec
maybe used to initialize the HKDF KeyGenerator to omit the extract step and
only expand a secret key from the input prk:
// the input key:
byte[] prk = ...;
// the info string:
byte[] info = ...;
// the length of the output key:
byte[] l = ...;
// create a HKDF KeyGenerator for the desired hash function:
KeyGenerator hkdf = KeyGenerator.getInstance("HKDFwithSHA256");
// initialize the HKDF:
HKDFExpandOnlyParameterSpec hkdfParamSpec = new HKDFExpandOnlyParameterSpec(prk, info, L);
hkdf.init(hkdfParamSpec, null);
// generate the key:
SecretKey key = hkdf.generateKey();
| Constructor and Description |
|---|
HKDFExpandOnlyParameterSpec(byte[] prk,
byte[] info,
int l)
Creates a HKDFExpandOnlyParameterSpec for the given pseudo-random key,
optional context and application specific information and length of
the output keying material.
|
HKDFExpandOnlyParameterSpec(javax.crypto.SecretKey prk,
byte[] info,
int l)
Creates a HKDFExpandOnlyParameterSpec for the given pseudo-random key,
optional context and application specific information and length of
the output keying material.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getInfo()
Gets the optional context and application specific information.
|
int |
getL()
Gets the length of output keying material in octets.
|
javax.crypto.SecretKey |
getPRK()
Gets the pseudo-random key.
|
public HKDFExpandOnlyParameterSpec(javax.crypto.SecretKey prk,
byte[] info,
int l)
prk - the pseudo-random key (of at least HashLen octets)info - the optional context and application specific information (may be
null)l - the length of output keying material in octets (<= 255*hashLen)public HKDFExpandOnlyParameterSpec(byte[] prk,
byte[] info,
int l)
prk - the pseudo-random key (as byte array of at least HashLen octets)info - the optional context and application specific information (may be a
null)l - the length of output keying material in octets (<= 255*hashLen)public javax.crypto.SecretKey getPRK()
public byte[] getInfo()
null if it has not been setpublic int getL()