javax.crypto

Class SecretKeyFactory

public class SecretKeyFactory extends Object

A secret key factory translates {@link SecretKey} objects to and from {@link java.security.spec.KeySpec} objects, and can translate between different vendors' representations of {@link SecretKey} objects (for security or semantics; whichever applies).

Since: 1.4

See Also: SecretKey

Constructor Summary
protected SecretKeyFactory(SecretKeyFactorySpi skfSpi, Provider provider, String algorithm)
Create a new secret key factory.
Method Summary
SecretKeygenerateSecret(KeySpec keySpec)
Generate a secret key from a key specification, if possible.
StringgetAlgorithm()
Get the algorithm name.
static SecretKeyFactorygetInstance(String algorithm)
Create a new secret key factory from the first appropriate instance.
static SecretKeyFactorygetInstance(String algorithm, String provider)
Create a new secret key factory from the named provider.
static SecretKeyFactorygetInstance(String algorithm, Provider provider)
Create a new secret key factory from the specified provider.
KeySpecgetKeySpec(SecretKey key, Class keySpec)
Get the key specification from a secret key.
ProvidergetProvider()
Get the provider of this implementation.
SecretKeytranslateKey(SecretKey key)
Translate a secret key into another form.

Constructor Detail

SecretKeyFactory

protected SecretKeyFactory(SecretKeyFactorySpi skfSpi, Provider provider, String algorithm)
Create a new secret key factory.

Parameters: skfSpi The underlying factory implementation. provider The provider. algorithm The algorithm name.

Method Detail

generateSecret

public final SecretKey generateSecret(KeySpec keySpec)
Generate a secret key from a key specification, if possible.

Parameters: keySpec The key specification.

Returns: The secret key.

Throws: java.security.InvalidKeySpecException If the key specification cannot be transformed into a secret key.

getAlgorithm

public final String getAlgorithm()
Get the algorithm name.

Returns: The algorithm name.

getInstance

public static final SecretKeyFactory getInstance(String algorithm)
Create a new secret key factory from the first appropriate instance.

Parameters: algorithm The algorithm name.

Returns: The appropriate key factory, if found.

Throws: NoSuchAlgorithmException If no provider implements the specified algorithm. IllegalArgumentException if algorithm is null or is an empty string.

getInstance

public static final SecretKeyFactory getInstance(String algorithm, String provider)
Create a new secret key factory from the named provider.

Parameters: algorithm The algorithm name. provider The provider name.

Returns: The appropriate key factory, if found.

Throws: NoSuchAlgorithmException If the named provider does not implement the algorithm. NoSuchProviderException If the named provider does not exist. IllegalArgumentException if either algorithm or provider is null, or if algorithm is an empty string.

getInstance

public static final SecretKeyFactory getInstance(String algorithm, Provider provider)
Create a new secret key factory from the specified provider.

Parameters: algorithm The algorithm name. provider The provider.

Returns: The appropriate key factory, if found.

Throws: NoSuchAlgorithmException If the provider does not implement the algorithm. IllegalArgumentException if either algorithm or provider is null, or if algorithm is an empty string.

getKeySpec

public final KeySpec getKeySpec(SecretKey key, Class keySpec)
Get the key specification from a secret key.

Parameters: key The secret key. keySpec The target key specification class.

Returns: The key specification.

Throws: java.security.spec.InvalidKeySpecException If the secret key cannot be transformed into the specified key specification.

getProvider

public final Provider getProvider()
Get the provider of this implementation.

Returns: The provider.

translateKey

public final SecretKey translateKey(SecretKey key)
Translate a secret key into another form.

Parameters: key The key to translate.

Returns: The translated key.

Throws: java.security.InvalidKeyException If the argument cannot be translated.