iaik.security.dsa
Class DSAKeyPairGenerator

java.lang.Object
  |
  +--java.security.KeyPairGeneratorSpi
        |
        +--java.security.KeyPairGenerator
              |
              +--iaik.security.dsa.DSAKeyPairGenerator
All Implemented Interfaces:
DSAKeyPairGenerator

public class DSAKeyPairGenerator
extends KeyPairGenerator
implements DSAKeyPairGenerator

Key pair generator for DSA keys as specified in FIPS PUB 186.

Valid length for the modulus is any multiple of 64 in the range of 512 to 1024.

This class contains precalculated public DSA parameters for modulus lengths of 512, 768, and 1024 bits. For other key lengths the parameters have to be calculated first, which is extremely slow (usually several minutes, depending on your luck and machine speed). However, when DSA parameters are available, key generation is very fast, therefore I recommend to stay with 512, 768, or 1024 bits.

To create a DSA key pair, 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 is set to 1024 bits.

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

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

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

 DSAKeyPairGenerator dsa_key_gen = (DSAKeyPairGenerator)key_gen;
 dsa_key_gen.initialize(dsa_params, sec_random);
 

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

Version:
File Revision 19
See Also:
KeyPairGenerator, KeyPair, DSA, RawDSA, DSAPublicKey, DSAPrivateKey, DSAKeyFactory, DSAParams

Constructor Summary
DSAKeyPairGenerator()
          Default constructor for creating a DSAKeyPairGenerator object.
 
Method Summary
 KeyPair generateKeyPair()
          Actually generates the requested KeyPair.
 void initialize(AlgorithmParameterSpec params, SecureRandom random)
          Initializes this DSAKeyPairGenerator with given DSAParameterSpec and random seed.
 void initialize(DSAParams params, SecureRandom random)
          Initializes this DSAKeyPairGenerator with given DSA parameters and random seed.
 void initialize(int strength)
          Initializes this DSAKeyPairGenerator for given modulus length.
 void initialize(int modlen, boolean genParams, SecureRandom random)
          Initializes this DSAKeyPairGenerator for given modulus length with the given random seed.
 void initialize(int strength, SecureRandom random)
          Initializes this DSAKeyPairGenerator for given 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

DSAKeyPairGenerator

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

initialize

public void initialize(int strength)
Initializes this DSAKeyPairGenerator for given modulus length.
Overrides:
initialize in class KeyPairGenerator

initialize

public void initialize(int strength,
                       SecureRandom random)
Initializes this DSAKeyPairGenerator for given modulus length with the given random seed.
Overrides:
initialize in class KeyPairGenerator
Parameters:
strength - the length of the modulus (any multiple of 64 in the range of 512 to 1024)
random - the random seed as SecureRandom

initialize

public void initialize(DSAParams params,
                       SecureRandom random)
                throws InvalidParameterException
Initializes this DSAKeyPairGenerator with given DSA parameters and random seed.
Specified by:
initialize in interface DSAKeyPairGenerator
Parameters:
params - the DSAParams representing prime p, sub-prime q, and base g
random - the random seed as SecureRandom
Throws:
InvalidParameterException - if the given parameters to not match to DSAParams

initialize

public void initialize(int modlen,
                       boolean genParams,
                       SecureRandom random)
                throws InvalidParameterException
Initializes this DSAKeyPairGenerator for given modulus length with the given random seed. This method initializes the generator either with precomputed DSA parameter values p, q and g (when genParams is set to false), or by generating new DSA parameter values (when genParams is set to true). Precomputed parameters are available for modulus length of either 512, 768, or 1024 bits.
Specified by:
initialize in interface DSAKeyPairGenerator
Parameters:
modlen - the length of the modulus in bits (512, 768, or 1024)
genParams - true for generating new parameters, false for using precomputed values for p, q and g
random - the random seed as SecureRandom
Throws:
InvalidParameterException - if the given modulus length is not a multiple of 64 between 512 and 1024 when genParms = true; or the given modulus length is not 512, 768, or 1024 when when genParms = false

initialize

public void initialize(AlgorithmParameterSpec params,
                       SecureRandom random)
                throws InvalidAlgorithmParameterException
Initializes this DSAKeyPairGenerator with given DSAParameterSpec and random seed.
Overrides:
initialize in class KeyPairGenerator
Parameters:
params - the DSAParamaterSpec representing p, q and g for initializing this generator
random - the random seed as SecureRandom
Throws:
InvalidAlgorithmParameterException - if the given parameter specification is not a DSAParameterSpec

generateKeyPair

public KeyPair generateKeyPair()
Actually generates the requested 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