public class KDF1
extends javax.crypto.KeyGeneratorSpi
This class implements the Key Derivation Function (KDF) 1, defined in ISO/IEC 18033-2. A KDF is a function which derives keying material of desired length from a shared secret and additional, optional information. The KDF itself is further parameterized with, e.g., a cryptographic hash function.
An application which wants to use KDF1 has to obtain it via the KeyGenerator engine class.
KeyGenerator kdf1 = KeyGenerator.getInstance("KDF1", ""IAIK)
A caller has to configure the KDF1 with a cryptographic hash function, like
SHA2-256, SHA3-256,...
. For that, use KDF1ParameterSpec.
An example usage may look like this:
AlgorithmID hashAlg = ...; int keyLength = ...; byte[] secretValue = ... KDF1ParameterSpec spec = new KDF1ParameterSpec(hashAlg, keyLength); spec.setSecretValue(secretValue); kg.init(spec); SecretKey key = (SecretKey) kg.generateKey();
If an implementation tries to use the KDF1 without a call to engineInit(AlgorithmParameterSpec, SecureRandom), the class will throw an exception.
KDF1ParameterSpec
Modifier and Type | Field and Description |
---|---|
static ObjectID |
OID
The ASN.1 object identifier (1.0.18033.2.5.1) for the KDF1 key derivation
function.
|
Constructor and Description |
---|
KDF1() |
Modifier and Type | Method and Description |
---|---|
protected javax.crypto.SecretKey |
engineGenerateKey()
Generates a key according to the specification of KDF1 with the provided
information.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec paramSpec,
java.security.SecureRandom random)
Initializes the KDF1 with the provided AlgorithmParameterSpec.
|
protected void |
engineInit(int keysize,
java.security.SecureRandom random)
This method is not supported as the caller has to initiate the class
with a KDF1ParameterSpec.
|
protected void |
engineInit(java.security.SecureRandom random)
This method is not supported as the caller has to initiate the class
with a KDF1ParameterSpec.
|
protected HashBasedGenerationFunction |
generateHBGF(KDF1ParameterSpec spec)
Intern helper function to create an instance of HashBasedGenerationFunction.
|
protected java.lang.String |
name()
Outputs the algorithm name.
|
public static final ObjectID OID
protected java.lang.String name()
protected HashBasedGenerationFunction generateHBGF(KDF1ParameterSpec spec)
protected void engineInit(java.security.SecureRandom random)
This method is not supported as the caller has to initiate the class with a KDF1ParameterSpec.
engineInit
in class javax.crypto.KeyGeneratorSpi
protected void engineInit(int keysize, java.security.SecureRandom random)
This method is not supported as the caller has to initiate the class with a KDF1ParameterSpec.
engineInit
in class javax.crypto.KeyGeneratorSpi
protected void engineInit(java.security.spec.AlgorithmParameterSpec paramSpec, java.security.SecureRandom random) throws java.security.InvalidAlgorithmParameterException
engineInit
in class javax.crypto.KeyGeneratorSpi
paramSpec
- an instance of AlgorithmParameterSpecrandom
- may be null
as it will be ignoredjava.security.InvalidAlgorithmParameterException
- if the caller provides AlgorithmParameterSpec
which are inappropriate to initialize the object.protected javax.crypto.SecretKey engineGenerateKey()
Generates a key according to the specification of KDF1 with the provided information. This method returns an instance of SecretKey. To obtain the secret, call SecretKey.getEncoded().
engineGenerateKey
in class javax.crypto.KeyGeneratorSpi
InternalErrorException
- if the caller did not initialize the object accordingly.