Package javax.crypto

Class SecretKeyFactory


  • public class SecretKeyFactory
    extends java.lang.Object
    This 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 SecretKeyFactory algorithms:

    • DES
    • DESede
    These algorithms are described 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.
    Since:
    1.4
    See Also:
    SecretKey, PBEKeySpec
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SecretKey generateSecret​(KeySpec keySpec)
      Generates a SecretKey object from the provided key specification (key material).
      java.lang.String getAlgorithm()
      Returns the algorithm name of this SecretKeyFactory object.
      static SecretKeyFactory getInstance​(java.lang.String algorithm)
      Returns a SecretKeyFactory object that converts secret keys of the specified algorithm.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static final SecretKeyFactory getInstance​(java.lang.String algorithm)
                                                  throws NoSuchAlgorithmException
        Returns a 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.

        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 SecretKeyFactory object.
        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 this SecretKeyFactory object.

        This is the same name that was specified in one of the getInstance calls that created this SecretKeyFactory object.

        Returns:
        the algorithm name of this SecretKeyFactory object.
      • generateSecret

        public final SecretKey generateSecret​(KeySpec keySpec)
                                       throws InvalidKeySpecException
        Generates a SecretKey object 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.