public class

SecretKeyFactory

extends Object
java.lang.Object
   ↳ javax.crypto.SecretKeyFactory

Class Overview

The public API for SecretKeyFactory implementations.

Secret key factories provide the following functionality:

  • convert SecretKey objects to and from KeySpec objects
  • translate SecretKey objects from one provider implementation to another
Which key specifications are supported by the generateSecret(KeySpec) and getKeySpec(SecretKey, Class) is provider dependent.

Summary

Protected Constructors
SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)
Creates a new SecretKeyFactory
Public Methods
final SecretKey generateSecret(KeySpec keySpec)
Generate a secret key from the specified key specification.
final String getAlgorithm()
Returns the name of the secret key algorithm.
final static SecretKeyFactory getInstance(String algorithm, String provider)
Creates a new SecretKeyFactory instance for the specified key algorithm from the specified provider.
final static SecretKeyFactory getInstance(String algorithm, Provider provider)
Creates a new SecretKeyFactory instance for the specified key algorithm from the specified provider.
final static SecretKeyFactory getInstance(String algorithm)
Creates a new SecretKeyFactory instance for the specified key algorithm.
final KeySpec getKeySpec(SecretKey key, Class keySpec)
Returns the key specification of the specified secret key.
final Provider getProvider()
Returns the provider for this SecretKeyFactory instance.
final SecretKey translateKey(SecretKey key)
Translates the specified secret key into an instance of the corresponding key from the provider of this key factory.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected SecretKeyFactory (SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)

Since: API Level 1

Creates a new SecretKeyFactory

Parameters
keyFacSpi the SPI delegate.
provider the provider providing this key factory.
algorithm the algorithm name for the secret key.

Public Methods

public final SecretKey generateSecret (KeySpec keySpec)

Since: API Level 1

Generate a secret key from the specified key specification.

Parameters
keySpec the key specification.
Returns
  • a secret key.
Throws
InvalidKeySpecException if the specified key specification cannot be used to generate a secret key.

public final String getAlgorithm ()

Since: API Level 1

Returns the name of the secret key algorithm.

Returns
  • the name of the secret key algorithm.

public static final SecretKeyFactory getInstance (String algorithm, String provider)

Since: API Level 1

Creates a new SecretKeyFactory instance for the specified key algorithm from the specified provider.

Parameters
algorithm the name of the key algorithm.
provider the name of the provider that provides the requested algorithm.
Returns
  • a secret key factory for the specified key algorithm from the specified provider.
Throws
NoSuchAlgorithmException if the specified provider cannot provide the requested algorithm.
NoSuchProviderException if the specified provider does not exist.
IllegalArgumentException if the specified provider name is null or empty.

public static final SecretKeyFactory getInstance (String algorithm, Provider provider)

Since: API Level 1

Creates a new SecretKeyFactory instance for the specified key algorithm from the specified provider.

Parameters
algorithm the name of the key algorithm.
provider the provider that provides the requested algorithm.
Returns
  • a secret key factory for the specified key algorithm from the specified provider.
Throws
NoSuchAlgorithmException if the specified provider cannot provider the requested algorithm.
IllegalArgumentException if the specified provider is null.
NullPointerException is the specified algorithm name is null.

public static final SecretKeyFactory getInstance (String algorithm)

Since: API Level 1

Creates a new SecretKeyFactory instance for the specified key algorithm.

Parameters
algorithm the name of the key algorithm.
Returns
  • a secret key factory for the specified key algorithm.
Throws
NoSuchAlgorithmException if no installed provider can provide the requested algorithm.
NullPointerException if the specified algorithm is null.

public final KeySpec getKeySpec (SecretKey key, Class keySpec)

Since: API Level 1

Returns the key specification of the specified secret key.

Parameters
key the secret key to get the specification from.
keySpec the target key specification class.
Returns
  • an instance of the specified key specification class.
Throws
InvalidKeySpecException if the specified secret key cannot be transformed into the requested key specification.

public final Provider getProvider ()

Since: API Level 1

Returns the provider for this SecretKeyFactory instance.

Returns
  • the provider for this SecretKeyFactory instance.

public final SecretKey translateKey (SecretKey key)

Since: API Level 1

Translates the specified secret key into an instance of the corresponding key from the provider of this key factory.

Parameters
key the secret key to translate.
Returns
  • the corresponding translated key.
Throws
InvalidKeyException if the specified key cannot be translated using this key factory.