public class SecretKeyFactory extends Object
Key factories are used to convert keys (opaque cryptographic keys of type Key) into key
specifications (transparent representations of the underlying key material), and vice versa. Secret key factories
operate only on secret (symmetric) keys.
Key factories are bi-directional, i.e., they allow to build an opaque key object from a given key specification (key material), or to retrieve the underlying key material of a key object in a suitable format.
Every implementation of the Java platform is required to support the following standard SecretKeyFactory
algorithms:
DESDESedeSecretKey,
PBEKeySpec| Modifier and Type | Method and Description |
|---|---|
SecretKey |
generateSecret(KeySpec keySpec)
Generates a
SecretKey object from the provided key specification (key material). |
String |
getAlgorithm()
Returns the algorithm name of this
SecretKeyFactory object. |
static SecretKeyFactory |
getInstance(String algorithm)
Returns a
SecretKeyFactory object that converts secret keys of the specified algorithm. |
public final SecretKey generateSecret(KeySpec keySpec) throws InvalidKeySpecException
SecretKey object from the provided key specification (key material).keySpec - the specification (key material) of the secret keyInvalidKeySpecException - if the given key specification is inappropriate for this secret-key factory to produce a secret
key.public final String getAlgorithm()
SecretKeyFactory object.
This is the same name that was specified in one of the getInstance calls that created this
SecretKeyFactory object.
SecretKeyFactory object.public static final SecretKeyFactory getInstance(String algorithm) throws NoSuchAlgorithmException
SecretKeyFactory object that converts secret keys of the specified algorithm.
This method traverses the list of registered security Providers, starting with the most preferred Provider. A new SecretKeyFactory object encapsulating the SecretKeyFactorySpi implementation from the first Provider that supports the specified algorithm is returned.
algorithm - the standard name of the requested secret-key algorithm. See the SecretKeyFactory section in the
Signature section of the Java Security Standard Algorithm Names Specification. Consult the release
documentation for your implementation to see if any other algorithms are supported.SecretKeyFactory object.NullPointerException - if the specified algorithm is null.NoSuchAlgorithmException - if no Provider supports a SecretKeyFactorySpi implementation for the specified algorithm.