public final class Hkdf
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
byte[] |
deriveKey(byte[] info,
int length)
Returns a pseudorandom key of
length bytes. |
void |
deriveKey(byte[] info,
int length,
byte[] output,
int offset)
Derives a pseudorandom key of
length bytes and stores the result in output
. |
byte[] |
deriveKey(java.lang.String info,
int length)
Returns a pseudorandom key of
length bytes. |
static Hkdf |
getInstance(java.lang.String algorithm)
Returns an
Hkdf object using the specified algorithm. |
static Hkdf |
getInstance(java.lang.String algorithm,
java.security.Provider provider)
Returns an
Hkdf object using the specified algorithm. |
static Hkdf |
getInstance(java.lang.String algorithm,
java.lang.String provider)
Returns an
Hkdf object using the specified algorithm. |
void |
init(byte[] ikm)
Initializes this Hkdf with input keying material.
|
void |
init(byte[] ikm,
byte[] salt)
Initializes this Hkdf with input keying material and a salt.
|
void |
unsafeInitWithoutKeyExtraction(javax.crypto.SecretKey rawKey)
Initializes this Hkdf to use the provided key directly for creation of new keys.
|
public static Hkdf getInstance(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException
Hkdf object using the specified algorithm.algorithm - the standard name of the requested MAC algorithm. See the Mac section in the
Java Cryptography Architecture Standard Algorithm Name Documentation for information
about standard algorithm names.Hkdf objectjava.security.NoSuchAlgorithmException - if no Provider supports a MacSpi implementation for the
specified algorithm.public static Hkdf getInstance(java.lang.String algorithm, java.lang.String provider) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException
Hkdf object using the specified algorithm.algorithm - the standard name of the requested MAC algorithm. See the Mac section in the
Java Cryptography Architecture Standard Algorithm Name Documentation for information
about standard algorithm names.provider - the name of the providerHkdf objectjava.security.NoSuchAlgorithmException - if a MacSpi implementation for the specified algorithm is not
available from the specified provider.java.security.NoSuchProviderException - if the specified provider is not registered in the security
provider list.public static Hkdf getInstance(java.lang.String algorithm, java.security.Provider provider) throws java.security.NoSuchAlgorithmException
Hkdf object using the specified algorithm.algorithm - the standard name of the requested MAC algorithm. See the Mac section in the
Java Cryptography Architecture Standard Algorithm Name Documentation for information
about standard algorithm names.provider - the providerHkdf objectjava.security.NoSuchAlgorithmException - if a MacSpi implementation for the specified algorithm is not
available from the specified provider.public void init(byte[] ikm)
ikm - the Input Keying Materialpublic void init(byte[] ikm,
byte[] salt)
salt is null or of length 0, then a default salt of HashLen zeros will be
used (where HashLen is the length of the return value of the supplied algorithm).salt - the salt used for key extraction (optional)ikm - the Input Keying Materialpublic void unsafeInitWithoutKeyExtraction(javax.crypto.SecretKey rawKey)
throws java.security.InvalidKeyException
rawKey is not securely generated and uniformly distributed over the total key-space,
then this will result in an insecure key derivation function (KDF). DO NOT USE THIS UNLESS
YOU ARE ABSOLUTELY POSITIVE THIS IS THE CORRECT THING TO DO.rawKey - the pseudorandom key directly used to derive keysjava.security.InvalidKeyException - if the algorithm for rawKey does not match the
algorithm this Hkdf was created withpublic byte[] deriveKey(java.lang.String info,
int length)
throws java.lang.IllegalStateException
length bytes.info - optional context and application specific information (can be a zero-length
string). This will be treated as UTF-8.length - the length of the output key in byteslength bytes.java.lang.IllegalStateException - if this object has not been initializedpublic byte[] deriveKey(byte[] info,
int length)
throws java.lang.IllegalStateException
length bytes.info - optional context and application specific information (can be a zero-length array).length - the length of the output key in byteslength bytes.java.lang.IllegalStateException - if this object has not been initializedpublic void deriveKey(byte[] info,
int length,
byte[] output,
int offset)
throws javax.crypto.ShortBufferException,
java.lang.IllegalStateException
length bytes and stores the result in output
.info - optional context and application specific information (can be a zero-length array).length - the length of the output key in bytesoutput - the buffer where the pseudorandom key will be storedoffset - the offset in output where the key will be storedjavax.crypto.ShortBufferException - if the given output buffer is too small to hold the resultjava.lang.IllegalStateException - if this object has not been initialized