de.cscc.crypto.provider
Class DES1KeySecretKeyGeneratorEngine

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

public final class DES1KeySecretKeyGeneratorEngine
extends KeyGeneratorSpi

DES1KeySecretKeyGeneratorEngine Class provides the functionality of a DESede key generator for two keys (means 56 or 64 bit key length). This key generator generates only keys for the "DES1Key" 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 DES1KeySecretKeyGeneratorEngine through the JCE in the following way:

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

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

 //Use key further in a DES1Key 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 highest-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("DES1Key", "JHBCI");
 SecretKey key = kg.generateKey();

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

 

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

Constructor Summary
DES1KeySecretKeyGeneratorEngine()
          Creates new DES1KeySecretKeyGeneratorEngine.
 
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

DES1KeySecretKeyGeneratorEngine

public DES1KeySecretKeyGeneratorEngine()
Creates new DES1KeySecretKeyGeneratorEngine. 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 56 bit and 64 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.