Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Cryptix V3.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.security
Class KeyGenerator

    java.lang.Object
      |
      +--java.security.KeyGenerator

Direct Known Subclasses:
  RawKeyGenerator

public abstract class KeyGenerator
extends Object
implements Parameterized

The KeyGenerator class is used to generate keys for a given algorithm. Key generators are constructed using the `getInstance` factory methods (static methods that return instances of a given class).

The KeyGenerator interface is entirely algorithm independent, and, as for the KeyPairGenerator instances, KeyGenerator instances may be cast to algorithm-specific interfaces defined elsewhere in the Java Cryptography Architecture.

A typical set of calls would be:

        import java.security.KeyGenerator;

        SecureRandom random = new SecureRandom();
        KeyGenerator keygen = KeyGenerator.getInstance("DES");
        keygen.initialize(random);
        Key key = keygen.generateKey();

Copyright © 1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.2 $

Since:
  IJCE 1.0.0
Author:
  David Hopwood, Raif S. Naffah

Constructor Summary
`protected` | `KeyGenerator(String algorithm)` Creates a KeyGenerator object for the specified algorithm.

Method Summary
`Object` | `clone()` Returns a clone of this key generator.
`protected Object` | `engineGetParameter(String param)` SPI: Gets the value of the specified algorithm parameter.
`protected void` | `engineSetParameter(String param, Object value)` SPI: Sets the specified algorithm parameter to the specified value.
`abstract SecretKey` | `generateKey()` Generates a key.
`String` | `getAlgorithm()` Returns the standard name of the algorithm for this key generator.
`static String[]` | `getAlgorithms()` Gets the standard names of all KeyGenerators implemented by any installed provider.
`static String[]` | `getAlgorithms(Provider provider)` Gets the standard names of all KeyGenerators implemented by a provider.
`static KeyGenerator` | `getInstance(String algorithm)` Generates a KeyGenerator object that implements the algorithm requested, as available in the environment.
`static KeyGenerator` | `getInstance(String algorithm, String provider)` Generates a KeyGenerator object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.
`Object` | `getParameter(String param)` Gets the value of the specified algorithm parameter.
`abstract void` | `initialize(SecureRandom random)` Initializes the key generator.
`void` | `setParameter(String param, Object value)` Sets the specified algorithm parameter to the specified value.
`String` | `toString()`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### KeyGenerator

    protected KeyGenerator(String algorithm)

  Creates a KeyGenerator object for the specified algorithm.
  Parameters:
    `algorithm` - the standard string name of the algorithm.
  Throws:
    NullPointerException - if algorithm == null

Method Detail

### getInstance

    public static KeyGenerator getInstance(String algorithm)
                                    throws NoSuchAlgorithmException

  Generates a KeyGenerator object that implements the algorithm requested, as available in the environment.

  See International JCE Standard Algorithm Names for a list of KeyGenerator algorithm names.

  Parameters:
    `algorithm` - the standard name or an alias for the algorithm.
  Returns:
    the new KeyGenerator object.
  Throws:
    NoSuchAlgorithmException - if the algorithm is not available in the environment.

### getInstance

    public static KeyGenerator getInstance(String algorithm,
                                           String provider)
                                    throws NoSuchAlgorithmException,
                                           NoSuchProviderException

  Generates a KeyGenerator object implementing the specified algorithm, as supplied from the specified provider, if such an algorithm is available from the provider.

  See International JCE Standard Algorithm Names for a list of KeyGenerator algorithm names.

  Parameters:
    `algorithm` - the standard name or an alias for the algorithm.
    `provider` - the string name of the provider.
  Returns:
    the new KeyGenerator object.
  Throws:
    NoSuchAlgorithmException - if the algorithm is not available from the provider.
    NoSuchProviderException - if the provider is not available in the environment.

### getAlgorithm

    public String getAlgorithm()

  Returns the standard name of the algorithm for this key generator.

  See International JCE Standard Algorithm Names for a list of KeyGenerator algorithm names.

  Returns:
    the standard string name of the algorithm.

### initialize

    public abstract void initialize(SecureRandom random)

  Initializes the key generator.
  Parameters:
    `random` - a source of randomness for this generator.

### generateKey

    public abstract SecretKey generateKey()

  Generates a key. This method generates a new key every time it is called.
  Returns:
    the new key.

### setParameter

    public void setParameter(String param,
                             Object value)
                      throws NoSuchParameterException,
                             InvalidParameterException,
                             InvalidParameterTypeException

  Sets the specified algorithm parameter to the specified value.

  This method supplies a general-purpose mechanism through which it is possible to set the various parameters of this object. A uniform algorithm-specific naming scheme for each parameter is desirable but left unspecified at this time.

  This method is not supported in JavaSoft's version of JCE.

  Specified by:
    setParameter in interface Parameterized
  Parameters:
    `param` - the string identifier of the parameter.
    `value` - the parameter value.
  Throws:
    NullPointerException - if param == null
    NoSuchParameterException - if there is no parameter with name param for this key generator implementation.
    InvalidParameterException - if the parameter exists but cannot be set.
    InvalidParameterTypeException - if value is the wrong type for this parameter.

### getParameter

    public Object getParameter(String param)
                        throws NoSuchParameterException,
                               InvalidParameterException

  Gets the value of the specified algorithm parameter.

  This method supplies a general-purpose mechanism through which it is possible to get the various parameters of this object. A uniform algorithm-specific naming scheme for each parameter is desirable but left unspecified at this time.

  This method is not supported in JavaSoft's version of JCE.

  Specified by:
    getParameter in interface Parameterized
  Parameters:
    `param` - the string name of the parameter.
  Returns:
    the object that represents the parameter value.
  Throws:
    NullPointerException - if param == null
    NoSuchParameterException - if there is no parameter with name param for this key generator implementation.
    InvalidParameterException - if the parameter exists but cannot be read.

### engineSetParameter

    protected void engineSetParameter(String param,
                                      Object value)
                               throws NoSuchParameterException,
                                      InvalidParameterException,
                                      InvalidParameterTypeException

  SPI: Sets the specified algorithm parameter to the specified value.

  This method supplies a general-purpose mechanism through which it is possible to set the various parameters of this object. A uniform algorithm-specific naming scheme for each parameter is desirable but left unspecified at this time.

  The default implementation always throws a NoSuchParameterException.

  This method is not supported in JavaSoft's version of JCE.

  Parameters:
    `param` - the string name of the parameter.
    `value` - the parameter value.
  Throws:
    NoSuchParameterException - if there is no parameter with name param for this key generator implementation.
    InvalidParameterException - if the parameter exists but cannot be set.
    InvalidParameterTypeException - if value is the wrong type for this parameter.

### engineGetParameter

    protected Object engineGetParameter(String param)
                                 throws NoSuchParameterException,
                                        InvalidParameterException

  SPI: Gets the value of the specified algorithm parameter.

  This method supplies a general-purpose mechanism through which it is possible to get the various parameters of this object. A uniform algorithm-specific naming scheme for each parameter is desirable but left unspecified at this time.

  The default implementation always throws a NoSuchParameterException.

  This method is not supported in JavaSoft's version of JCE.

  Parameters:
    `param` - the string name of the parameter.
  Returns:
    the object that represents the parameter value.
  Throws:
    NoSuchParameterException - if there is no parameter with name param for this key generator implementation.
    InvalidParameterException - if the parameter exists but cannot be read.

### clone

    public Object clone()
                 throws CloneNotSupportedException

  Returns a clone of this key generator.

  Note: In JavaSoft's version of JCE, `KeyGenerator.clone()` is protected. This is not very useful, since then an application (as opposed to the key generator implementation itself) is not able to call it.

  Overrides:
    clone in class Object
  Throws:
    CloneNotSupportedException - if the key generator is not cloneable.

### toString

    public String toString()

  Overrides:
    toString in class Object

### getAlgorithms

    public static String[] getAlgorithms(Provider provider)

  Gets the standard names of all KeyGenerators implemented by a provider.

  This method is not supported in JavaSoft's version of JCE. For compatibility you may wish to use `IJCE.getAlgorithms(provider, "KeyGenerator")` instead.

  Since:
    IJCE 1.0.1

### getAlgorithms

    public static String[] getAlgorithms()

  Gets the standard names of all KeyGenerators implemented by any installed provider. Algorithm names are not duplicated if they are supported by more than one provider.

  This method is not supported in JavaSoft's version of JCE. For compatibility you may wish to use `IJCE.getAlgorithms("KeyGenerator")` instead.

  Since:
    IJCE 1.0.1

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Cryptix V3.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) 1995-2000 The Cryptix Foundation Ltd. All rights reserved.