iaik.security.dh
Class DHKeyPairGenerator

java.lang.Object
  |
  +--java.security.KeyPairGeneratorSpi
        |
        +--java.security.KeyPairGenerator
              |
              +--iaik.security.dh.DHKeyPairGenerator

public class DHKeyPairGenerator
extends KeyPairGenerator

Key pair generator for DH keys to be used for Diffie Hellman key agreement.

The Diffie Hellman algorithm has been the first public-key algorithm. It only can be used for key-agreement, but not for data encrypting and decrypting.

PKCS#3 describes a method for implementing the Diffie Hellman key agreement where two (or more) entities use general Diffie Hellman parameters (an odd prime p, an integer base g satisfying 0 < g < p, and optionally an integer l prescribing the length of the private value), generated from some central authority (which may an entity itself), to create a shared secret, only known by them.

For creating a DH key pair necessary for performing a Diffie Hellman key agreement, a KeyPairGenerator has to be instantiated, properly initialized and directed to actually generate the keys by calling the generateKeyPair method. If the generator is not initialized by explicitly calling an initialize method, the modulus length per default is set to 1024 bits.

Generating DH keys using a modulus length of, e.g. 1024 bits (explicitly initialized), may be done by:

KeyPairGenerator key_gen = KeyPairGenerator.getIntance("DH");
 key_gen.initialize(1024, sec_random);
 KeyPair key_pair = key_gen.generateKeyPair();
 

The example above initializes the key pair generator algorithm-independently by only specifying the length of the modulus. For performing an algorithm-specific initialization, an explicit cast to DHKeyPairGenerator would be necessary, e.g.:

 DHKeyPairGenerator dh_key_gen = (DHKeyPairGenerator)key_gen;
 dh_key_gen.initialize(dh_param_spec, sec_random);

Guidelines on how to create key pairs using a KeyPairGenerator can be found in http://java.sun.com/products/JDK/1.1/docs/guide/security/CryptoSpec.html.

Version:
File Revision 17
See Also:
KeyPairGenerator, KeyPair, DHPublicKey, DHPrivateKey, DHKeyFactory, DHKeyAgreement, DHParameterSpec

Constructor Summary
DHKeyPairGenerator()
          Default constructor for creating a DHKeyPairGenerator object.
 
Method Summary
 KeyPair generateKeyPair()
          Actually generates the requested DH KeyPair.
 void initialize(AlgorithmParameterSpec param, SecureRandom random)
          Initializes this DHKeyPairGenerator with given DH parameter specification and random seed.
 void initialize(int primeLength)
          Initializes the DHKeyPairGenerator for given prime modulus length.
 void initialize(int primeLength, SecureRandom random)
          Initializes the DHKeyPairGenerator for given prime modulus length with the given random seed.
 
Methods inherited from class java.security.KeyPairGenerator
genKeyPair, getAlgorithm, getInstance, getInstance, getProvider, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DHKeyPairGenerator

public DHKeyPairGenerator()
Default constructor for creating a DHKeyPairGenerator object.
Method Detail

initialize

public void initialize(int primeLength)
Initializes the DHKeyPairGenerator for given prime modulus length.

Overrides:
initialize in class KeyPairGenerator
Parameters:
primLength - the length of the prime modulus in bits

initialize

public void initialize(int primeLength,
                       SecureRandom random)
Initializes the DHKeyPairGenerator for given prime modulus length with the given random seed.

Overrides:
initialize in class KeyPairGenerator
Parameters:
primLength - the length of the prime modulus in bits
random - the random seed as SecureRandom.

initialize

public void initialize(AlgorithmParameterSpec param,
                       SecureRandom random)
                throws InvalidAlgorithmParameterException
Initializes this DHKeyPairGenerator with given DH parameter specification and random seed.

Overrides:
initialize in class KeyPairGenerator
Parameters:
param - the DHParameterSpec representing prime modulus p, base ganerator g, and exponent length l
random - the random seed as SecureRandom
Throws:
InvalidParameterException - if the given algorithm parameter specification is not a DHParameterSpec or the size of the exponent is not shorter than that of the prime modulus, both derived from the given DH parameter specification

generateKeyPair

public KeyPair generateKeyPair()
Actually generates the requested DH KeyPair.

Overrides:
generateKeyPair in class KeyPairGenerator
Returns:
the requested key pair

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK