Class HKDFParameterSpec.Builder
- Enclosing interface:
HKDFParameterSpecPREVIEW
Builder
is a preview API of the Java platform.
Builder
builds Extract
and ExtractThenExpand
objects.
The Builder
is initialized via the ofExtract
method of
HKDFParameterSpec
. As stated in the class description,
addIKM
and/or addSalt
may be called as needed. Finally,
an object is "built" by calling either extractOnly
or
thenExpand
for Extract
and ExtractThenExpand
use-cases respectively. Note that the Builder
is not
thread-safe.
- Since:
- 24
-
Method Summary
Modifier and TypeMethodDescriptionaddIKM
(byte[] ikm) Adds input keying material (IKM) to the builder.Adds input keying material (IKM) to the builder.addSalt
(byte[] salt) Adds a salt to the builder.Adds a salt to the builder.Builds anExtract
object from the current state of theBuilder
.thenExpand
(byte[] info, int length) Builds anExtractThenExpand
object from the current state of theBuilder
.
-
Method Details
-
extractOnly
Builds anExtract
object from the current state of theBuilder
.- Returns:
- an immutable
Extract
object
-
thenExpand
Builds anExtractThenExpand
object from the current state of theBuilder
.- Implementation Note:
- HKDF implementations will enforce that the length is not greater than 255 * HMAC length. HKDF implementations will also enforce that a {code null} info value is treated as zero-length byte array.
- Parameters:
info
- the optional context and application specific information (may benull
); the byte array is cloned to prevent subsequent modificationlength
- the length of the output keying material (must be greater than 0)- Returns:
- an immutable
ExtractThenExpand
object - Throws:
IllegalArgumentException
- iflength
is not greater than 0
-
addIKM
Adds input keying material (IKM) to the builder.Users may call
addIKM
multiple times when the input keying material value is to be assembled piece-meal or if part of the IKM is to be supplied by a hardware crypto device. Theikms()
method of theExtract
orExtractThenExpand
object that is subsequently built returns the assembled input keying material as a list ofSecretKey
objects.- Parameters:
ikm
- the input keying material (IKM) value- Returns:
- this builder
- Throws:
NullPointerException
- if theikm
argument is null
-
addIKM
Adds input keying material (IKM) to the builder. Note that anikm
byte array of length zero will be discarded.Users may call
addIKM
multiple times when the input keying material value is to be assembled piece-meal or if part of the IKM is to be supplied by a hardware crypto device. Theikms()
method of theExtract
orExtractThenExpand
object that is subsequently built returns the assembled input keying material as a list ofSecretKey
objects.- Parameters:
ikm
- the input keying material (IKM) value; theikm
byte array will be converted to aSecretKeySpec
, which means that the byte array will be cloned inside theSecretKeySpec
constructor- Returns:
- this builder
- Throws:
NullPointerException
- if theikm
argument is null
-
addSalt
Adds a salt to the builder.Users may call
addSalt
multiple times when the salt value is to be assembled piece-meal or if part of the salt is to be supplied by a hardware crypto device. Thesalts()
method of theExtract
orExtractThenExpand
object that is subsequently built returns the assembled salt as a list ofSecretKey
objects.- Parameters:
salt
- the salt value- Returns:
- this builder
- Throws:
NullPointerException
- if thesalt
is null
-
addSalt
Adds a salt to the builder. Note that asalt
byte array of length zero will be discarded.Users may call
addSalt
multiple times when the salt value is to be assembled piece-meal or if part of the salt is to be supplied by a hardware crypto device. Thesalts()
method of theExtract
orExtractThenExpand
object that is subsequently built returns the assembled salt as a list ofSecretKey
objects.- Parameters:
salt
- the salt value; thesalt
byte array will be converted to aSecretKeySpec
, which means that the byte array will be cloned inside theSecretKeySpec
constructor- Returns:
- this builder
- Throws:
NullPointerException
- if thesalt
is null
-
Builder
when preview features are enabled.