The AlgorithmParameterGenerator Class

The AlgorithmParameterGenerator class is an engine class used to generate a set of parameters suitable for a certain algorithm (the algorithm specified when an AlgorithmParameterGenerator instance is created).

Creating an AlgorithmParameterGenerator Object
As with all engine classes, the way to get an AlgorithmParameterGenerator object for a particular type of algorithm is to call the getInstance static factory method on the AlgorithmParameterGenerator class:
static AlgorithmParameterGenerator getInstance( String algorithm)
Note: The algorithm name is not case-sensitive.
A caller can optionally specify the name of a provider or the Provider class, which will guarantee that the algorithm parameter generator implementation is from the named provider:
static AlgorithmParameterGenerator getInstance( String algorithm, String provider)
static AlgorithmParameterGenerator getInstance( String algorithm, Provider provider)
Initializing an AlgorithmParameterGenerator Object

The AlgorithmParameterGenerator object can be initialized in two different ways: an algorithm-independent manner or an algorithm-specific manner.

The algorithm-independent approach uses the fact that all parameter generators share the concept of a size and a source of randomness. The measure of size is universally shared by all algorithm parameters, though it is interpreted differently for different algorithms. For example, in the case of parameters for the DSA algorithm, size corresponds to the size of the prime modulus, in bits. (See Appendix B: Algorithms for information about the sizes for specific algorithms.) When using this approach, algorithm-specific parameter generation values--if any--default to some standard values. One init method that takes these two universally shared types of arguments:
void init(int size, SecureRandom random);
Another init method takes only a size argument and uses a system-provided source of randomness:
void init(int size)
A third approach initializes a parameter generator object using algorithm-specific semantics, which are represented by a set of algorithm-specific parameter generation values supplied in an AlgorithmParameterSpec object:
void init(AlgorithmParameterSpec genParamSpec, SecureRandom random)
void init(AlgorithmParameterSpec genParamSpec)

To generate Diffie-Hellman system parameters, for example, the parameter generation values usually consist of the size of the prime modulus and the size of the random exponent, both specified in number of bits. (The Diffie-Hellman algorithm has been part of the JCE since JCE 1.2.)

Generating Algorithm Parameters
After you have created and initialized an AlgorithmParameterGenerator object, you can use the generateParameters method to generate the algorithm parameters:
AlgorithmParameters generateParameters()