public class PBKDF2Parameters
extends java.security.AlgorithmParametersSpi
PKCS#5 specifies a method for encrypting messages with secret keys derived from a password. PBKDF2 parameters specify salt value, iteration count, length of the to-be-derived key (optional), and (MAC based) pseudo random function (default: HMCA/SHA1) to be used by the PBKDF2 function for deriving a secret key from a password:
PBKDF2-params ::= SEQUENCE { salt CHOICE { specified OCTET STRING, otherSource AlgorithmIdentifier {{PBKDF2-SaltSources}} }, iterationCount INTEGER (1..MAX), keyLength INTEGER (1..MAX) OPTIONAL, prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1 }The PBKDF2-params ASN.1 definition allows to specify the salt value as OCTET STRING or otherSource algorithm id. However, this implementation does not support the otherSource alternative because until now it is not yet fully specified by PKCS#5 (version v2.1).
PBKDF2Parameters can be generated by calling one of the
AlgorithmParameters.getInstance
methods. Subsequently
the new AlgorithmParameters object must be initialized with a proper PBKDF2 parameter
specification or a DER encoded byte array, e.g.:
PBKDF2ParameterSpec paramSpec = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("PBKDF2", "IAIK"); params.init(paramSpec);respectively:
byte[] encodedParams = ...; AlgorithmParameters params = AlgorithmParameters.getInstance("PBKDF2", "IAIK"); params.init(encodedParams);
For obtaining PBKDF2 parameters in transparent
representation from an opaque PBKDF2Parameters object, the getParameterSpec
method can be used; for obtaining the parameters as DER encoded ASN.1 object, use method
getEncoded
:
PBKDF2ParameterSpec paramSpec = (PBKDF2ParameterSpec) params .getParameterSpec(PBKDF2ParameterSpec.class);respectively
byte[] encodedParams = params.getEncoded();
PBKDF2ParameterSpec
,
AlgorithmParameters
Constructor and Description |
---|
PBKDF2Parameters()
The default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
engineGetEncoded()
Returns the (DER) encoded PBKDF2 parameters.
|
protected byte[] |
engineGetEncoded(java.lang.String format)
Returns the (DER) encoded PBKDF2 parameters.
|
protected java.security.spec.AlgorithmParameterSpec |
engineGetParameterSpec(java.lang.Class paramSpec)
Returns the PBKDF2 parameters as transparent PBKDF2 parameter specification of the
given class type.
|
protected void |
engineInit(java.security.spec.AlgorithmParameterSpec paramSpec)
Initializes this PBKDF2Parameters with the given PBKDF2ParameterSpec.
|
protected void |
engineInit(byte[] params)
Initializes this PBKDF2Parameters object from the given DER encoded byte array.
|
protected void |
engineInit(byte[] params,
java.lang.String format)
Inits the parameters from an DER encoded byte array.
|
protected java.lang.String |
engineToString()
Returns a String representation of the parameters.
|
public PBKDF2Parameters()
PBKDF2Parameters
object.
Applications shall use one of the AlgorithmParameters.getInstance
factory methods for obtaining PBKDF2Parameters.protected byte[] engineGetEncoded() throws java.io.IOException
engineGetEncoded
in class java.security.AlgorithmParametersSpi
java.io.IOException
- if an encoding error occursprotected byte[] engineGetEncoded(java.lang.String format) throws java.io.IOException
Format is ignored. Only DER encoding is supported at this time. This method
only calls engineGetEncoded()
for returning the PBKDF2 parameters as DER encoded byte array, regardless of what
is specified in the format
string.
engineGetEncoded
in class java.security.AlgorithmParametersSpi
format
- the encoding format; ignoredjava.io.IOException
- if an encoding error occursprotected java.security.spec.AlgorithmParameterSpec engineGetParameterSpec(java.lang.Class paramSpec) throws java.security.spec.InvalidParameterSpecException
engineGetParameterSpec
in class java.security.AlgorithmParametersSpi
paramSpec
- the desired parameter specification class, must be PBKDF2ParameterSpec.class
java.security.spec.InvalidParameterSpecException
- if the parameters cannot be converted to
the desired parameter specificationprotected void engineInit(java.security.spec.AlgorithmParameterSpec paramSpec) throws java.security.spec.InvalidParameterSpecException
engineInit
in class java.security.AlgorithmParametersSpi
paramSpec
- the parameter specification, which has to be a PBKDF2ParameterSpecjava.security.spec.InvalidParameterSpecException
- if the given parameter specification
is not a PBKDF2ParameterSpecprotected void engineInit(byte[] params) throws java.io.IOException
engineInit
in class java.security.AlgorithmParametersSpi
params
- the DER encoded PBKDF2 parametersjava.io.IOException
- if an error occurs when decoding the given byte arrayprotected void engineInit(byte[] params, java.lang.String format) throws java.io.IOException
engineInit(params)
for initializing this PBKDF2Parameters object from
the given DER encoded byte array, regardless of what is specified in the format
string.engineInit
in class java.security.AlgorithmParametersSpi
params
- the DER encoded PBKDF2 parametersformat
- the encoding format; ignoredjava.io.IOException
- if an error occurs when decoding the given byte arrayprotected java.lang.String engineToString()
engineToString
in class java.security.AlgorithmParametersSpi