Class SecretKeyFactory
- java.lang.Object
-
- javax.crypto.SecretKeyFactory
-
public class SecretKeyFactory extends java.lang.ObjectThis class represents a factory for secret keys.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
SecretKeyFactoryalgorithms:DESDESede
- Since:
- 1.4
- See Also:
SecretKey,PBEKeySpec
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SecretKeygenerateSecret(KeySpec keySpec)Generates aSecretKeyobject from the provided key specification (key material).java.lang.StringgetAlgorithm()Returns the algorithm name of thisSecretKeyFactoryobject.static SecretKeyFactorygetInstance(java.lang.String algorithm)Returns aSecretKeyFactoryobject that converts secret keys of the specified algorithm.
-
-
-
Method Detail
-
getInstance
public static final SecretKeyFactory getInstance(java.lang.String algorithm) throws NoSuchAlgorithmException
Returns aSecretKeyFactoryobject 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.
- Parameters:
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.- Returns:
- the new
SecretKeyFactoryobject. - Throws:
java.lang.NullPointerException- if the specified algorithm is null.NoSuchAlgorithmException- if no Provider supports a SecretKeyFactorySpi implementation for the specified algorithm.
-
getAlgorithm
public final java.lang.String getAlgorithm()
Returns the algorithm name of thisSecretKeyFactoryobject.This is the same name that was specified in one of the
getInstancecalls that created thisSecretKeyFactoryobject.- Returns:
- the algorithm name of this
SecretKeyFactoryobject.
-
generateSecret
public final SecretKey generateSecret(KeySpec keySpec) throws InvalidKeySpecException
Generates aSecretKeyobject from the provided key specification (key material).- Parameters:
keySpec- the specification (key material) of the secret key- Returns:
- the secret key
- Throws:
InvalidKeySpecException- if the given key specification is inappropriate for this secret-key factory to produce a secret key.
-
-