public class DSAKeyPairGenerator
extends java.security.KeyPairGenerator
implements java.security.interfaces.DSAKeyPairGenerator
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.
KeyPairGenerator,
KeyPair,
DSA,
RawDSA,
DSAPublicKey,
DSAPrivateKey,
DSAKeyFactory,
DSAParams| Constructor and Description |
|---|
DSAKeyPairGenerator()
The constructor; creates a new instance of the DSA key pair generation
algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
java.security.KeyPair |
generateKeyPair()
Generates a key pair.
|
void |
initialize(java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
Initializes this DSAKeyPairGenerator with given DSAParameterSpec and
random seed.
|
void |
initialize(java.security.interfaces.DSAParams params,
java.security.SecureRandom random)
Initializes this DSAKeyPairGenerator with given DSA parameters and
user-provided source of randomness.
|
void |
initialize(int keysize)
Initializes the key pair generator for a certain keysize, using the
default parameter set.
|
void |
initialize(int modlen,
boolean genParams,
java.security.SecureRandom random)
Initializes this DSAKeyPairGenerator for given modulus length with the
user-provided source of randomness.
|
void |
initialize(int keysize,
java.security.SecureRandom random)
Initializes the key pair generator for a certain keysize, using the
default parameter set and user-provided source of randomness.
|
public DSAKeyPairGenerator()
Applications should not use this constructor, instead the key pair
generation algorithm should be requested from the appropriate JCA/JCE
cryptographic service provider as follows:
KeyPairGenerator.getInstance("DSA", "IAIK").
public void initialize(int keysize)
initialize in class java.security.KeyPairGeneratorkeysize - [FIPS 140-2 data input] the keysize. This is an
algorithm-specific metric, such as modulus length, specified
in number of bits.java.security.InvalidParameterException - [FIPS 140-2 status output] if the keysize is
not supportedpublic void initialize(int keysize,
java.security.SecureRandom random)
initialize in class java.security.KeyPairGeneratorkeysize - [FIPS 140-2 data input] the keysize. This is an
algorithm-specific metric, such as modulus length, specified
in number of bits.random - [FIPS 140-2 control input] the source of randomness for this
generator.java.security.InvalidParameterException - [FIPS 140-2 status output] if the keysize is
not supportedpublic void initialize(java.security.interfaces.DSAParams params,
java.security.SecureRandom random)
throws java.security.InvalidParameterException
initialize in interface java.security.interfaces.DSAKeyPairGeneratorparams - [FIPS 140-2 data input] the DSAParams representing prime
p, sub-prime q, and base
grandom - [FIPS 140-2 control input] the source of randomness for this
generator.java.security.InvalidParameterException - [FIPS 140-2 status output] if the given parameters to not
match to DSAParamspublic void initialize(int modlen,
boolean genParams,
java.security.SecureRandom random)
throws java.security.InvalidParameterException
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.
initialize in interface java.security.interfaces.DSAKeyPairGeneratormodlen - [FIPS 140-2 data input] the length of the modulus in bits
(512, 768, or 1024)genParams - [FIPS 140-2 control input] true for generating
new parameters, false for using precomputed
values for p, q and grandom - [FIPS 140-2 control input] the source of randomness for this
generator.java.security.InvalidParameterException - [FIPS 140-2 status output] 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 = falsepublic void initialize(java.security.spec.AlgorithmParameterSpec params,
java.security.SecureRandom random)
throws java.security.InvalidAlgorithmParameterException
initialize in class java.security.KeyPairGeneratorparams - [FIPS 140-2 data input] the DSAParamaterSpec representing p, q
and g for initializing this generatorrandom - [FIPS 140-2 control input] the source of randomness for this
generator.java.security.InvalidAlgorithmParameterException - [FIPS 140-2 status output] if the given parameter
specification is not a DSAParameterSpecpublic java.security.KeyPair generateKeyPair()
Unless an initialization method is called using a KeyPairGenerator interface, algorithm-specific defaults will be used. This will generate a new key pair every time it is called.
generateKeyPair in class java.security.KeyPairGeneratorFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operations