Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SecretKeyFactory

public class SecretKeyFactory
extends Object

java.lang.Object
   ↳ javax.crypto.SecretKeyFactory


The public API for SecretKeyFactory implementations.

Secret key factories provide the following functionality:

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.

Inherited methods

From class java.lang.Object

Protected constructors

SecretKeyFactory

Added in API level 1
SecretKeyFactory (SecretKeyFactorySpi keyFacSpi, 
                Provider provider, 
                String algorithm)

Creates a new SecretKeyFactory

Parameters
keyFacSpi SecretKeyFactorySpi: the SPI delegate.
provider Provider: the provider providing this key factory.
algorithm String: the algorithm name for the secret key.

Public methods

generateSecret

Added in API level 1
SecretKey generateSecret (KeySpec keySpec)

Generate a secret key from the specified key specification.

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

getAlgorithm

Added in API level 1
String getAlgorithm ()

Returns the name of the secret key algorithm.

Returns
String the name of the secret key algorithm.

getInstance

Added in API level 1
SecretKeyFactory getInstance (String algorithm, 
                String provider)

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

Parameters
algorithm String: the name of the key algorithm.
provider String: the name of the provider that provides the requested algorithm.
Returns
SecretKeyFactory 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.

getInstance

Added in API level 1
SecretKeyFactory getInstance (String algorithm, 
                Provider provider)

Creates a new SecretKeyFactory instance for the specified key algorithm from the specified provider. The provider supplied does not have to be registered.

Parameters
algorithm String: the name of the key algorithm.
provider Provider: the provider that provides the requested algorithm.
Returns
SecretKeyFactory 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.

getInstance

Added in API level 1
SecretKeyFactory getInstance (String algorithm)

Creates a new SecretKeyFactory instance for the specified key algorithm.

Parameters
algorithm String: the name of the key algorithm.
Returns
SecretKeyFactory 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.

getKeySpec

Added in API level 1
KeySpec getKeySpec (SecretKey key, 
                Class keySpec)

Returns the key specification of the specified secret key.

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

getProvider

Added in API level 1
Provider getProvider ()

Returns the provider for this SecretKeyFactory instance.

Returns
Provider the provider for this SecretKeyFactory instance.

translateKey

Added in API level 1
SecretKey translateKey (SecretKey key)

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

Parameters
key SecretKey: the secret key to translate.
Returns
SecretKey the corresponding translated key.
Throws
InvalidKeyException if the specified key cannot be translated using this key factory.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.