Class PBKDF2
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
org.opensaml.xmlsec.derivation.impl.PBKDF2
- All Implemented Interfaces:
Cloneable,Component,DestructableComponent,InitializableComponent,CloneableKeyAgreementParameter,KeyAgreementParameter,XMLExpressableKeyAgreementParameter,KeyDerivation
public class PBKDF2
extends AbstractInitializableComponent
implements KeyDerivation, XMLExpressableKeyAgreementParameter, CloneableKeyAgreementParameter
Implementation of PBKDF2 key derivation as defined in XML Encryption 1.1.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IntegerDefault length for generated salt, in bytes.static final IntegerDefault iteration count.static final StringDefault PRF.private IntegerGenerated salt length, in bytes.private IntegerIteration count.private IntegerKey length, in bits.private static final StringBase algorithm ID for PBKDF2 SecretKeyFactory.private StringPseudo-random function algorithm.private StringBase64-encoded salt value.private SecureRandomSecureRandom generator for salt. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBuild anXMLObjectinstance representing this parameter.clone()Clone the parameter instance.Derive aSecretKeyfrom the specified secret.protected voidstatic PBKDF2fromXMLObject(KeyDerivationMethod xmlObject) Create and initialize a new instance from the specifiedXMLObject.The key derivation algorithm URI.protected IntegergetEffectiveKeyLength(String keyAlgorithm, Integer specifiedKeyLength) Get the effective key length, in bits.protected byte[]Get the effective salt bytes to use.Get the generated salt length, in bytes.Get the iteration count.Get the key length, in number of bits.getPRF()Get the pseudo-random function algorithm URI.Get the secure random generator.getSalt()Get the Base64-encoded salt value.voidsetGeneratedSaltLength(Integer length) Set the generated salt length, in bytes.voidsetIterationCount(Integer count) Set the iteration count.voidsetKeyLength(Integer length) Set the key length, in number of bits.voidSet the pseudo-random function algorithm URI.voidSet the secure random generator.voidSet the Base64-encoded salt value.private static PBKDF2validateAndSetXMLObjectParameters(PBKDF2Params xmlParams) Validate thePBKDF2Paramsinstance.Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized
-
Field Details
-
DEFAULT_PRF
Default PRF.- See Also:
-
DEFAULT_ITERATION_COUNT
Default iteration count. -
DEFAULT_GENERATED_SALT_LENGTH
Default length for generated salt, in bytes. -
PBKDF2_JCA_ALGORITHM_BASE
Base algorithm ID for PBKDF2 SecretKeyFactory.- See Also:
-
salt
Base64-encoded salt value. -
generatedSaltLength
Generated salt length, in bytes. -
secureRandom
SecureRandom generator for salt. -
iterationCount
Iteration count. -
keyLength
Key length, in bits. -
prf
Pseudo-random function algorithm.
-
-
Constructor Details
-
PBKDF2
public PBKDF2()
-
-
Method Details
-
getAlgorithm
The key derivation algorithm URI.- Specified by:
getAlgorithmin interfaceKeyDerivation- Returns:
- the algorithm
-
getSalt
Get the Base64-encoded salt value.- Returns:
- the salt value
-
setSalt
Set the Base64-encoded salt value.- Parameters:
value- the salt
-
getGeneratedSaltLength
Get the generated salt length, in bytes.- Returns:
- the generated salt length, in bytes
-
setGeneratedSaltLength
Set the generated salt length, in bytes.- Parameters:
length- the generated salt length
-
getRandom
Get the secure random generator.Defaults to the platform default via
new SecureRandom()- Returns:
- the secure random instance
-
setRandom
Set the secure random generator.Defaults to the platform default via
new SecureRandom()- Parameters:
sr- the secure random generator to set
-
getIterationCount
Get the iteration count.- Returns:
- the iteration count
-
setIterationCount
Set the iteration count.- Parameters:
count- the iteration count
-
getKeyLength
Get the key length, in number of bits.Note: KeyLength in expressed XML will be in bytes
- Returns:
- the key length
-
setKeyLength
Set the key length, in number of bits.Note: KeyLength in expressed XML will be in bytes
- Parameters:
length- the key length
-
getPRF
Get the pseudo-random function algorithm URI.- Returns:
- the algorithm URI
-
setPRF
Set the pseudo-random function algorithm URI.- Parameters:
uri- the PRF URI
-
doInitialize
- Overrides:
doInitializein classAbstractInitializableComponent- Throws:
ComponentInitializationException
-
derive
@Nonnull public SecretKey derive(@Nonnull byte[] secret, @Nonnull String keyAlgorithm, @Nullable Integer specifiedKeyLength) throws KeyDerivationException Derive aSecretKeyfrom the specified secret.- Specified by:
derivein interfaceKeyDerivation- Parameters:
secret- the input secret from which to derive the key.keyAlgorithm- the algorithm URI for which the derived key will be usedspecifiedKeyLength- the length of the derived key. This may be null if the keyAlgorithm URI implies a key length, for example if the URI represents aKeyLengthSpecifiedAlgorithm. However if the URI implies a key length and this parameter value does not match that length, that is an error and and exception will be thrown- Returns:
- the derived key
- Throws:
KeyDerivationException- if the key derivation operation is not completed successfully
-
getEffectiveSalt
Get the effective salt bytes to use.- Returns:
- the salt bytes
- Throws:
KeyDerivationException- if the salt value can not be successfully resolved
-
getEffectiveKeyLength
protected Integer getEffectiveKeyLength(@Nonnull String keyAlgorithm, @Nullable Integer specifiedKeyLength) throws KeyDerivationException Get the effective key length, in bits.- Parameters:
keyAlgorithm- the algorithm for which the derived key will be usedspecifiedKeyLength- the explicitly specified key length- Returns:
- the effective key length, in bits
- Throws:
KeyDerivationException- if the key length can not be successfully resolved
-
clone
Clone the parameter instance.- Specified by:
clonein interfaceCloneableKeyAgreementParameter- Overrides:
clonein classObject- Returns:
- the cloned parameter
-
buildXMLObject
Build anXMLObjectinstance representing this parameter.- Specified by:
buildXMLObjectin interfaceXMLExpressableKeyAgreementParameter- Returns:
- the XML object instance
-
fromXMLObject
@Nonnull public static PBKDF2 fromXMLObject(@Nonnull KeyDerivationMethod xmlObject) throws ComponentInitializationException Create and initialize a new instance from the specifiedXMLObject.- Parameters:
xmlObject- the XML object- Returns:
- new parameter instance
- Throws:
ComponentInitializationException- if component initialization fails
-
validateAndSetXMLObjectParameters
@Nonnull private static PBKDF2 validateAndSetXMLObjectParameters(@Nonnull PBKDF2Params xmlParams) throws ComponentInitializationException Validate thePBKDF2Paramsinstance.- Parameters:
xmlParams- the instance to validate- Returns:
- the initialized
PBKDF2object - Throws:
ComponentInitializationException- if the specified params fails validation of required values
-