javax.crypto
Class SecretKeyFactory

java.lang.Object
  extended by javax.crypto.SecretKeyFactory

public class SecretKeyFactory
extends Object

A secret key factory translates SecretKey objects to and from KeySpec objects, and can translate between different vendors' representations of 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
 SecretKey generateSecret(KeySpec keySpec)
          Generate a secret key from a key specification, if possible.
 String getAlgorithm()
          Get the algorithm name.
static SecretKeyFactory getInstance(String algorithm)
          Create a new secret key factory from the first appropriate instance.
static SecretKeyFactory getInstance(String algorithm, Provider provider)
          Create a new secret key factory from the specified provider.
static SecretKeyFactory getInstance(String algorithm, String provider)
          Create a new secret key factory from the named provider.
 KeySpec getKeySpec(SecretKey key, Class keySpec)
          Get the key specification from a secret key.
 Provider getProvider()
          Get the provider of this implementation.
 SecretKey translateKey(SecretKey key)
          Translate a secret key into another form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getInstance

public static final SecretKeyFactory getInstance(String algorithm)
                                          throws NoSuchAlgorithmException
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)
                                          throws NoSuchAlgorithmException,
                                                 NoSuchProviderException
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)
                                          throws NoSuchAlgorithmException
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.

generateSecret

public final SecretKey generateSecret(KeySpec keySpec)
                               throws InvalidKeySpecException
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.
InvalidKeySpecException

getAlgorithm

public final String getAlgorithm()
Get the algorithm name.

Returns:
The algorithm name.

getKeySpec

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

Parameters:
key - The secret key.
keySpec - The target key specification class.
Returns:
The key specification.
Throws:
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)
                             throws InvalidKeyException
Translate a secret key into another form.

Parameters:
key - The key to translate.
Returns:
The translated key.
Throws:
InvalidKeyException - If the argument cannot be translated.