All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class cryptix.provider.key.RawKeyGenerator

java.lang.Object
   |
   +----java.security.KeyGenerator
           |
           +----cryptix.provider.key.RawKeyGenerator

public class RawKeyGenerator
extends KeyGenerator
implements ExtendedKeyGenerator, Cloneable
RawKeyGenerator acts as a superclass for other Cryptix key generator classes.

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

$Revision: 1.1.1.1 $

Author:
David Hopwood, Raif S. Naffah

Constructor Index

 o RawKeyGenerator(String, int)
Constructor for use by subclasses that require a fixed-length key.
 o RawKeyGenerator(String, int, int, int)
Constructor for use by subclasses that allow variable-length keys.

Method Index

 o engineGenerateKey(byte[])
This method allows subclasses to modify the bytes that will be used to generate a key.
 o generateKey()
Generates a key.
 o generateKey(byte[])
Generates a key from an encoded byte array.
 o getDefaultKeyLength()
Returns the key length that will be used by generateKey() to create new random keys.
 o getMaximumKeyLength()
Returns the maximum useful key length for this algorithm.
 o getMinimumKeyLength()
Returns the minimum key length for this algorithm.
 o initialize(SecureRandom)
Initializes the key generator.
 o initialize(SecureRandom, int)
Initializes the key generator, and sets a specific key length for use with algorithms that allow variable-length keys.
 o isValidKeyLength(int)
Returns true iff length is a valid key length (in bytes) for this algorithm.
 o isWeak(byte[])
Returns true iff key represents a weak or semi-weak key for this algorithm.
 o isWeakAllowed()
Returns true if this object is allowed to generate weak and semi-weak keys; false otherwise.
 o setWeakAllowed(boolean)
Sets whether this object is allowed to generate weak and semi-weak keys.

Constructors

 o RawKeyGenerator
 protected RawKeyGenerator(String algorithm,
                           int seedlength) throws IllegalArgumentException
Constructor for use by subclasses that require a fixed-length key. Each candidate key will be seedlength bytes long.

Note: seedlength does not correspond to a cryptographic strength. In particular, there is no implication that a brute-force attack against the algorithm would require 256^seedlength trials.

Parameters:
algorithm - the standard string name of the algorithm.
seedlength - the desired seed length in bytes.
Throws: IllegalArgumentException
if seedlength <= 0
 o RawKeyGenerator
 protected RawKeyGenerator(String algorithm,
                           int minlength,
                           int defaultlength,
                           int maxlength) throws IllegalArgumentException
Constructor for use by subclasses that allow variable-length keys. Each candidate key will be a minimum of minlength, and a maximum of maxlength bytes long. If the generateKey() method is used without any other parameters or initialization, the key will be defaultlength bytes long.

Note: none of these length parameters correspond to a cryptographic strength. In particular, there is no implication that a brute-force attack against the algorithm would require 256^(length of key) trials.

Parameters:
algorithm - the standard string name of the algorithm.
minlength - the minimum seed length in bytes.
defaultlength - the default seed length in bytes.
maxlength - the maximum useful seed length in bytes.
Throws: IllegalArgumentException
if !(0 < minlength && minlength <= defaultlength && defaultlength <= maxlength)

Methods

 o generateKey
 public SecretKey generateKey()
Generates a key. This method generates a new random key every time it is called.

If a source of random bytes has not been set using one of the initialize methods, new SecureRandom() will be used.

Returns:
the new key.
Overrides:
generateKey in class KeyGenerator
 o initialize
 public void initialize(SecureRandom random)
Initializes the key generator.

Parameters:
random - the source of randomness for this generator.
Overrides:
initialize in class KeyGenerator
 o initialize
 public void initialize(SecureRandom random,
                        int length)
Initializes the key generator, and sets a specific key length for use with algorithms that allow variable-length keys.

The length parameter only affects randomly generated keys (i.e. the generateKey() method without parameters).

Parameters:
random - the source of randomness for this generator.
length - the desired key length in bytes.
Throws: IllegalArgumentException
if length is not valid for this algorithm.
 o isWeakAllowed
 public boolean isWeakAllowed()
Returns true if this object is allowed to generate weak and semi-weak keys; false otherwise.

 o setWeakAllowed
 public void setWeakAllowed(boolean allowWeak)
Sets whether this object is allowed to generate weak and semi-weak keys.

Parameters:
allowWeak - true if weak/semi-weak keys are allowed.
 o getMinimumKeyLength
 public int getMinimumKeyLength()
Returns the minimum key length for this algorithm.

 o getDefaultKeyLength
 public int getDefaultKeyLength()
Returns the key length that will be used by generateKey() to create new random keys. This is either the default key length determined by the KeyGenerator for this algorithm, or the length set using initialize(SecureRandom random, int length).

 o getMaximumKeyLength
 public int getMaximumKeyLength()
Returns the maximum useful key length for this algorithm.

 o isValidKeyLength
 public boolean isValidKeyLength(int length)
Returns true iff length is a valid key length (in bytes) for this algorithm.

The default implementation returns true if length is between the minimum and maximum key lengths. Some algorithms will override this method to specify a more restricted set of values.

 o generateKey
 public SecretKey generateKey(byte data[]) throws WeakKeyException, InvalidKeyException
Generates a key from an encoded byte array. The format of the secret key is "RAW". The contents of data will not be modified.

The encoded key bytes may differ from data in order to make sure that they represent a valid key. For example, if keys for this algorithm conventionally include parity bits, those bits will be set correctly. For most algorithms, data is used unchanged.

Parameters:
data - user supplied raw-encoded data from which a secret key will be generated.
Returns:
the new key.
Throws: NullPointerException
if data == null
Throws: WeakKeyException
if isWeakAllowed() is false, and data represents a weak key for this algorithm.
Throws: InvalidKeyException
if the length of data is not valid for this algorithm.
 o engineGenerateKey
 protected byte[] engineGenerateKey(byte seed[]) throws WeakKeyException, InvalidKeyException
This method allows subclasses to modify the bytes that will be used to generate a key. This might be necessary in order to set parity bits, for example.

The seed array contains either randomly generated bytes, or an encoded form of the key. Subclasses should throw a WeakKeyException if isWeakAllowed() is false, and a weak key would have been generated.

The default implementation is as follows: If weak keys are not allowed, and the seed array represents a weak key (i.e. !isWeakAllowed() && isWeak(seed)), throw a WeakKeyException. Otherwise, just return the seed array. This is sufficient if the key does not have any special form (for example, parity bits that should be set correctly).

The seed array can be modified if that is convenient.

Parameters:
seed - the seed bytes for this key.
Returns:
the key encoding.
 o isWeak
 protected boolean isWeak(byte key[])
Returns true iff key represents a weak or semi-weak key for this algorithm. The length of the array is not checked, and an ArrayIndexOutOfBoundsException may be thrown if it is too short.

The default implementation returns false.


All Packages  Class Hierarchy  This Package  Previous  Next  Index