public class SecretKeyFactory extends Object
SecretKeyFactory implementations.
Secret key factories provide the following functionality:
SecretKey objects to and from KeySpec objectsSecretKey objects from one provider implementation to
anothergenerateSecret(java.security.spec.KeySpec) and
getKeySpec(javax.crypto.SecretKey, java.lang.Class) is provider dependent.| Modifier | Constructor and Description |
|---|---|
protected |
SecretKeyFactory(SecretKeyFactorySpi keyFacSpi,
Provider provider,
String algorithm)
Creates a new
SecretKeyFactory |
| Modifier and Type | Method and Description |
|---|---|
SecretKey |
generateSecret(KeySpec keySpec)
Generate a secret key from the specified key specification.
|
String |
getAlgorithm()
Returns the name of the secret key algorithm.
|
static SecretKeyFactory |
getInstance(String algorithm)
Creates a new
SecretKeyFactory instance for the specified key
algorithm. |
static SecretKeyFactory |
getInstance(String algorithm,
Provider provider)
Creates a new
SecretKeyFactory instance for the specified key
algorithm from the specified provider. |
static SecretKeyFactory |
getInstance(String algorithm,
String provider)
Creates a new
SecretKeyFactory instance for the specified key
algorithm from the specified provider. |
KeySpec |
getKeySpec(SecretKey key,
Class keySpec)
Returns the key specification of the specified secret key.
|
Provider |
getProvider()
Returns the provider for this
SecretKeyFactory instance. |
SecretKey |
translateKey(SecretKey key)
Translates the specified secret key into an instance of the corresponding
key from the provider of this key factory.
|
protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)
SecretKeyFactorykeyFacSpi - the SPI delegate.provider - the provider providing this key factory.algorithm - the algorithm name for the secret key.public final String getAlgorithm()
public final Provider getProvider()
SecretKeyFactory instance.SecretKeyFactory instance.public static final SecretKeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException
SecretKeyFactory instance for the specified key
algorithm.algorithm - the name of the key algorithm.NoSuchAlgorithmException - if no installed provider can provide the requested algorithm.NullPointerException - if the specified algorithm is null.public static final SecretKeyFactory getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
SecretKeyFactory instance for the specified key
algorithm from the specified provider.algorithm - the name of the key algorithm.provider - the name of the provider that provides the requested
algorithm.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) throws NoSuchAlgorithmException
SecretKeyFactory instance for the specified key
algorithm from the specified provider. The provider supplied
does not have to be registered.algorithm - the name of the key algorithm.provider - the provider that provides the requested algorithm.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 final SecretKey generateSecret(KeySpec keySpec) throws InvalidKeySpecException
keySpec - the key specification.InvalidKeySpecException - if the specified key specification cannot be used to generate
a secret key.public final KeySpec getKeySpec(SecretKey key, Class keySpec) throws InvalidKeySpecException
key - the secret key to get the specification from.keySpec - the target key specification class.InvalidKeySpecException - if the specified secret key cannot be transformed into the
requested key specification.public final SecretKey translateKey(SecretKey key) throws InvalidKeyException
key - the secret key to translate.InvalidKeyException - if the specified key cannot be translated using this key
factory.