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
AlgorithmParameterGeneratorObject - As with all engine classes, the way to get an
AlgorithmParameterGeneratorobject for a particular type of algorithm is to call thegetInstancestatic factory method on theAlgorithmParameterGeneratorclass:static AlgorithmParameterGenerator getInstance( String algorithm)Note: The algorithm name is not case-sensitive.A caller can optionally specify the name of a provider or theProviderclass, 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
AlgorithmParameterGeneratorObject -
The
AlgorithmParameterGeneratorobject 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. OneAnotherinitmethod that takes these two universally shared types of arguments:void init(int size, SecureRandom random);initmethod takes only asizeargument 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 anAlgorithmParameterSpecobject: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
AlgorithmParameterGeneratorobject, you can use thegenerateParametersmethod to generate the algorithm parameters:AlgorithmParameters generateParameters()