iaik.security.cipher
Class VarLengthKeyGenerator

java.lang.Object
  |
  +--javax.crypto.KeyGeneratorSpi
        |
        +--iaik.security.cipher.VarLengthKeyGenerator
Direct Known Subclasses:
CAST128KeyGenerator, RCxKeyGenerator

public abstract class VarLengthKeyGenerator
extends KeyGeneratorSpi

This class provides the functionality of KeyGenerator for generating keys with variable length. It is an abstract class that is used by a number of different keygenerators, e.g. RC4 or Blowfish.

An application uses e.g.

 KeyGenerator key_gen = KeyGenerator.getInstance("Blowfish");
 
to create a KeyGenerator object for the given algorithm. For actually generating the requested secret key from the KeyGenerator object just created, an application calls the generateKey method after having initialized the generator with some random seed or relied on the default system-provided source of randomness:

 SecretKey new_key = key_gen.generateKey();
 

See Also:
KeyGenerator, KeyGeneratorSpi, SecretKey, SecretKey

Constructor Summary
protected VarLengthKeyGenerator(java.lang.String algorithmName, int minLength, int maxLength, int defaultLength)
          Constructor for use by subclasses.
protected VarLengthKeyGenerator(java.lang.String algorithmName, int minLength, int maxLength, int defaultLength, int increment)
          Constructor for use by subclasses.
 
Method Summary
 SecretKey engineGenerateKey()
          Generates a new key.
 void engineInit(AlgorithmParameterSpec params, SecureRandom random)
          Initializes this key generator.
 void engineInit(int strength, SecureRandom random)
          Initializes this key generator for the given strength with the given random seed.
 void engineInit(SecureRandom random)
          Initializes this key generator with the given random seed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VarLengthKeyGenerator

protected VarLengthKeyGenerator(java.lang.String algorithmName,
                                int minLength,
                                int maxLength,
                                int defaultLength,
                                int increment)
Constructor for use by subclasses.

VarLengthKeyGenerator

protected VarLengthKeyGenerator(java.lang.String algorithmName,
                                int minLength,
                                int maxLength,
                                int defaultLength)
Constructor for use by subclasses.
Method Detail

engineInit

public void engineInit(AlgorithmParameterSpec params,
                       SecureRandom random)
                throws InvalidAlgorithmParameterException
Initializes this key generator. If params is not null, otherwise this call is identical to engineInit(random).
Overrides:
engineInit in class KeyGeneratorSpi
Throws:
InvalidAlgorithmParameterException - if parameters are passed

engineInit

public void engineInit(int strength,
                       SecureRandom random)
Initializes this key generator for the given strength with the given random seed. Lengths outside the range of minimum to maximum length default to the default length.
Overrides:
engineInit in class KeyGeneratorSpi
Parameters:
strength - the strength of the key to be created
random - the random seed

engineInit

public void engineInit(SecureRandom random)
Initializes this key generator with the given random seed. The strength defaults to the default length.
Overrides:
engineInit in class KeyGeneratorSpi
Parameters:
random - the random seed for this generator

engineGenerateKey

public SecretKey engineGenerateKey()
Generates a new key.
Overrides:
engineGenerateKey in class KeyGeneratorSpi
Returns:
the created key
See Also:
SecretKey