de.cscc.crypto.provider
Class DESede2KeySecretKeyGeneratorEngine

java.lang.Object
  extended byjavax.crypto.KeyGeneratorSpi
      extended byde.cscc.crypto.provider.DESede2KeySecretKeyGeneratorEngine

public final class DESede2KeySecretKeyGeneratorEngine
extends KeyGeneratorSpi

DESede2KeySecretKeyGeneratorEngine Class provides the functionality of a DESede key generator for two keys (means 112 or 128 bit key length). This key generator generates only keys for the "DESede2Key" algorithm in the JHBCI crypto provider. This KeyGenerator Object is re-useable, i.e., after a key has been generated, the same KeyGenerator Object can be re-used to generate further keys.


 Use the DESede2KeySecretKeyGeneratorEngine through the JCE in the following 
 way:

 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 import java.security.SecureRandom;

 KeyGenerator kg = new KeyGenerator.getInstance("DESede2Key", "JHBCI");
 kg.init(new SecureRandom());
 SecretKey key = kg.generateKey();

 //Use key further in a DESede2Key Cipher from the JHBCI provider.
 //Or do some other useful things with this nicely generated SecretKey.

 
In this case you does not explicitly initialize the KeyGenerator Object (in our example code that means kg.init(new SecureRandom());) we initialize the KeyGenerator Object with new SecureRandom(). So you can omit the line kg.init(new SecureRandom());. With this code we will get a SecureRandom implementation of the higest-priority installed provider. If no one of the installed providers supply an implementation of SecureRandom, a system provided source of randomness will be used.

 See the changed example:

 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 import java.security.SecureRandom;

 KeyGenerator kg = new KeyGenerator.getInstance("DESede2Key", "JHBCI");
 SecretKey key = kg.generateKey();

 //Use key further in a DESede2Key Cipher from the JHBCI provider.
 //Or do some other useful things with this nicely generated SecretKey.

 

Version:
$Revision: 1.12 $
Author:
Uwe Günther

Constructor Summary
DESede2KeySecretKeyGeneratorEngine()
          Creates new DESede2KeySecretKeyGeneratorEngine.
 
Method Summary
protected  SecretKey engineGenerateKey()
          Generates a secret key.
protected  void engineInit(AlgorithmParameterSpec params, SecureRandom random)
          Initializes the key generator with the specified parameter set and a user-provided source of randomness.
protected  void engineInit(int keysize, SecureRandom random)
          Initializes this key generator for a certain keysize, using the given source of randomness.
protected  void engineInit(SecureRandom random)
          Initializes the key generator.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DESede2KeySecretKeyGeneratorEngine

public DESede2KeySecretKeyGeneratorEngine()
Creates new DESede2KeySecretKeyGeneratorEngine. Mostly used of the static function KeyGenerator.getInstance(...).

Throws:
SecurityException - if the provider self integrity check fails.
Method Detail

toString

public String toString()
Returns a string representation of the object.

Returns:
a string representation of the object.

engineInit

protected void engineInit(SecureRandom random)
Initializes the key generator.

Parameters:
random - the source of randomness for this generator.

engineInit

protected void engineInit(int keysize,
                          SecureRandom random)
                   throws InvalidParameterException
Initializes this key generator for a certain keysize, using the given source of randomness. We support only 112 bit and 128 bit keysize, which means the refers to the same result.

Parameters:
keysize - the keysize. This is an algorithm-specific metric, specified in number of bits.
random - the source of randomness for this key generator.
Throws:
InvalidParameterException - if keysize is wrong or not supported.

engineInit

protected void engineInit(AlgorithmParameterSpec params,
                          SecureRandom random)
                   throws InvalidAlgorithmParameterException
Initializes the key generator with the specified parameter set and a user-provided source of randomness. The JHBCI key generator implementation don't use any AlgorithmParameterSpec's. This means if you want to init the KeyGenerator Object with this method params have to be null or InvalidAlgorithmParameterException will be thrown.

Parameters:
params - the key generation parameters.
random - the source of randomness for this key generator.
Throws:
InvalidAlgorithmParameterException - if params is inappropriate for this key generator. We only support null as parameter for params.

engineGenerateKey

protected SecretKey engineGenerateKey()
Generates a secret key. This method can re-used more than once for the KeyGenerator Object to generate a lot of SecretKey's.

Returns:
the new key.


Copyright © 2001, 2002 by Uwe Günther. See the COPYING file for more details. Browse the source as HTML.