Package javax.crypto
Class SecretKeyFactory
java.lang.Object
javax.crypto.SecretKeyFactory
public class SecretKeyFactory extends Object
The public API for
SecretKeyFactory implementations.
Secret key factories provide the following functionality:
- convert
SecretKeyobjects to and fromKeySpecobjects - translate
SecretKeyobjects from one provider implementation to another
generateSecret(java.security.spec.KeySpec) and
getKeySpec(javax.crypto.SecretKey, java.lang.Class) is provider dependent.-
Constructor Summary
Constructors Modifier Constructor Description protectedSecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)Creates a newSecretKeyFactory -
Method Summary
Modifier and Type Method Description SecretKeygenerateSecret(KeySpec keySpec)Generate a secret key from the specified key specification.StringgetAlgorithm()Returns the name of the secret key algorithm.static SecretKeyFactorygetInstance(String algorithm)Creates a newSecretKeyFactoryinstance for the specified key algorithm.static SecretKeyFactorygetInstance(String algorithm, String provider)Creates a newSecretKeyFactoryinstance for the specified key algorithm from the specifiedprovider.static SecretKeyFactorygetInstance(String algorithm, Provider provider)Creates a newSecretKeyFactoryinstance for the specified key algorithm from the specified provider.KeySpecgetKeySpec(SecretKey key, Class keySpec)Returns the key specification of the specified secret key.ProvidergetProvider()Returns the provider for thisSecretKeyFactoryinstance.SecretKeytranslateKey(SecretKey key)Translates the specified secret key into an instance of the corresponding key from the provider of this key factory.
-
Constructor Details
-
SecretKeyFactory
Creates a newSecretKeyFactory- Parameters:
keyFacSpi- the SPI delegate.provider- the provider providing this key factory.algorithm- the algorithm name for the secret key.
-
-
Method Details
-
getAlgorithm
Returns the name of the secret key algorithm.- Returns:
- the name of the secret key algorithm.
-
getProvider
Returns the provider for thisSecretKeyFactoryinstance.- Returns:
- the provider for this
SecretKeyFactoryinstance.
-
getInstance
Creates a newSecretKeyFactoryinstance 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 isnull.
-
getInstance
public static final SecretKeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderExceptionCreates a newSecretKeyFactoryinstance for the specified key algorithm from the specifiedprovider.- 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 isnullor empty.
-
getInstance
public static final SecretKeyFactory getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmExceptionCreates a newSecretKeyFactoryinstance 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 isnull.NullPointerException- is the specified algorithm name isnull.
-
generateSecret
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.
-
getKeySpec
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.
-
translateKey
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.
-