javax.crypto
Class SecretKeyFactory

java.lang.Object
  |
  +--javax.crypto.SecretKeyFactory

public class SecretKeyFactory
extends Object

Key factory for secret keys.


Attention:  This is not a SUN implementation!

This class has been developed by IAIK according to the documentation publically available.
For SUNīs documentation of this class see http://java.sun.com/security/JCE1.2/spec/apidoc/index.html


This class represents a factory for secret keys, as used by symmetric ciphers. Keys may appear in two representations within the Java Security environment:

SecretKey factories are used for converting keys from one representation into the other.

To convert, for instance, DES key material (e.g. des_key_spec instantiated from DESKeySpec) from transparent to opaque representation, use the SecretKeyFactory for DES keys (if supported by the actual provider):

 SecretKeyFactory des_key_fac = SecretKeyFactory.getInstance("DES");
 SecretKey des_key = des_key_fac.generateSecret(des_key_spec);
 

Version:
File Revision 16
See Also:
SecretKey, DESKeySpec, DESedeKeySpec, PBEKeySpec

Constructor Summary
protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi, Provider provider, String algorithm)
          Creates a SecretKeyFactory object.
 
Method Summary
 SecretKey generateSecret(KeySpec keySpec)
          Converts the given key specification (key material) into a SecretKey object.
 String getAlgorithm()
          Returns the standard name of the key algorithm.
static SecretKeyFactory getInstance(String algorithm)
          Returns the default provider SecretKeyFactory object for the specified symmetric algorithm.
static SecretKeyFactory getInstance(String algorithm, String provider)
          Returns a SecretKeyFactory object for the specified symmetric algorithm, implemented by the given provider.
 KeySpec getKeySpec(SecretKey key, Class keySpec)
          Converts the given secret key into the requested key specification (key material).
 Provider getProvider()
          Returns the provider used for creating this SecretKeyFactory object.
 SecretKey translateKey(SecretKey key)
          Translates a key object of some unknown or untrusted provider into a secret key object of this key factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SecretKeyFactory

protected SecretKeyFactory(SecretKeyFactorySpi keyFacSpi,
                           Provider provider,
                           String algorithm)
Creates a SecretKeyFactory object. Only internally used for creating a SecretKeyFactory object. Applications shall use one of the getInstance factory methods for obtaining a SecretKeyFactory object.
Parameters:
keyFacSpi - the SPI SecretKeyFactory implementation of the actual provider
provider - the provider
Method Detail

getInstance

public static final SecretKeyFactory getInstance(String algorithm)
                                          throws NoSuchAlgorithmException
Returns the default provider SecretKeyFactory object for the specified symmetric algorithm.
Parameters:
algorithm - the standard name of the symmetric algorithm, e.g. "DES
Returns:
a SecretKeyFactory object for the given symmetric algorithm, supplied by the default provider
Throws:
NoSuchAlgorithmException - if the specified algorithm is not implemented

getInstance

public static final SecretKeyFactory getInstance(String algorithm,
                                                 String provider)
                                          throws NoSuchAlgorithmException,
                                                 NoSuchProviderException
Returns a SecretKeyFactory object for the specified symmetric algorithm, implemented by the given provider.
Parameters:
algorithm - the standard name of the symmetric algorithm, e.g. "DES
provider - the name of the requested provider.
Returns:
a SecretKeyFactory object, supplied by the specified provider
Throws:
NoSuchAlgorithmException - if the specified algorithm is not implemented
NoSuchProviderException - if this provider cannot be fetched

getProvider

public final Provider getProvider()
Returns the provider used for creating this SecretKeyFactory object.
Returns:
the provider used for creating this SecretKeyFactory object

getAlgorithm

public final String getAlgorithm()
Returns the standard name of the key algorithm.
Returns:
the standard name of the algorithm as string.

generateSecret

public final SecretKey generateSecret(KeySpec keySpec)
                               throws InvalidKeySpecException
Converts the given key specification (key material) into a SecretKey object.
Parameters:
keySpec - the specification (key material) to be converted into SecretKey representation.
Returns:
the SecretKey object
Throws:
InvalidKeySpecException - if the given key material cannot be converted into a SecretKey object by this key factory

getKeySpec

public final KeySpec getKeySpec(SecretKey key,
                                Class keySpec)
                         throws InvalidKeySpecException
Converts the given secret key into the requested key specification (key material).
Parameters:
key - the secret key to be converted.
keySpec - the key specification type into which the secret key shall be converted
Returns:
the key specification (key material) derived from the given secret key
Throws:
InvalidKeySpecException - if the given secret key cannot be converted into the requested key specification object by this key factory

translateKey

public final SecretKey translateKey(SecretKey key)
                             throws InvalidKeyException
Translates a key object of some unknown or untrusted provider into a secret key object of this key factory.
Parameters:
key - the key of some unknown or untrusted provider
Returns:
the translated key
Throws:
InvalidKeyException - if the given key cannot be translated by this key factory

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK