Class HKDFParameterSpec.Builder

java.lang.Object
javax.crypto.spec.HKDFParameterSpec.Builder
Enclosing interface:
HKDFParameterSpecPREVIEW

public static final class HKDFParameterSpec.Builder extends Object
Builder is a preview API of the Java platform.
Programs can only use Builder when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
This 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, the object is "built" by calling either extractOnly or thenExpand for Extract and ExtractThenExpand use-cases respectively.

Since:
23
  • Method Details

    • extractOnly

      public HKDFParameterSpec.ExtractPREVIEW extractOnly()
      Builds an Extract.
      Returns:
      an immutable Extract
    • thenExpand

      public HKDFParameterSpec.ExtractThenExpandPREVIEW thenExpand(byte[] info, int length)
      Builds an ExtractThenExpand.
      Parameters:
      info - the optional context and application specific information (may be null); the byte[] is copied to prevent subsequent modification
      length - the length of the output key material
      Returns:
      an ExtractThenExpand
      Throws:
      IllegalArgumentException - if length is not > 0
    • addIKM

      Adds input key material to the builder.

      addIKM may be called when the input key material value is to be assembled piece-meal or if part of the IKM is to be supplied by a hardware crypto device. This method appends to the existing list of values or creates a new list if there is none yet.

      This supports the use-case where a label can be applied to the IKM but the actual value of the IKM is not yet available.

      An implementation should concatenate the input key materials into a single value once all components are available.

      Parameters:
      ikm - the input key material value
      Returns:
      this builder
      Throws:
      NullPointerException - if the ikm is null
    • addIKM

      public HKDFParameterSpec.BuilderPREVIEW addIKM(byte[] ikm)
      Adds input key material to the builder.

      addIKM may be called when the input key material value is to be assembled piece-meal or if part of the IKM is to be supplied by a hardware crypto device. This method appends to the existing list of values or creates a new list if there is none yet.

      This supports the use-case where a label can be applied to the IKM but the actual value of the IKM is not yet available.

      An implementation should concatenate the input key materials into a single value once all components are available.

      Parameters:
      ikm - the input key material value
      Returns:
      this builder
      Throws:
      NullPointerException - if the ikm is null
    • addSalt

      Adds a salt to the builder.

      addSalt may be called 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. This method appends to the existing list of values or creates a new list if there is none yet.

      This supports the use-case where a label can be applied to the salt but the actual value of the salt is not yet available.

      An implementation should concatenate the salt into a single value once all components are available.

      Parameters:
      salt - the salt value
      Returns:
      this builder
      Throws:
      NullPointerException - if the salt is null
    • addSalt

      public HKDFParameterSpec.BuilderPREVIEW addSalt(byte[] salt)
      Adds a salt to the builder.

      addSalt may be called 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. This method appends to the existing list of values or creates a new list if there is none yet.

      This supports the use-case where a label can be applied to the salt but the actual value of the salt is not yet available. An implementation should concatenate the salt into a single value once all components are available.

      Parameters:
      salt - the salt value
      Returns:
      this builder
      Throws:
      NullPointerException - if the salt is null