43
43
import java.security.spec.AlgorithmParameterSpec;
46
* <p>The <code>AlgorithmParameterGenerator</code> class is used to generate a
47
* set of parameters to be used with a certain algorithm. Parameter generators
48
* are constructed using the <code>getInstance()</code> factory methods (static
49
* methods that return instances of a given class).</p>
51
* <p>The object that will generate the parameters can be initialized in two
52
* different ways: in an algorithm-independent manner, or in an
53
* algorithm-specific manner:</p>
56
* <li>The algorithm-independent approach uses the fact that all parameter
57
* generators share the concept of a <i>"size"</i> and a <i>source of
58
* randomness</i>. The measure of <i>size</i> is universally shared by all
59
* algorithm parameters, though it is interpreted differently for different
60
* algorithms. For example, in the case of parameters for the <i>DSA</i>
61
* algorithm, <i>"size"</i> corresponds to the size of the prime modulus (in
62
* bits). When using this approach, algorithm-specific parameter generation
63
* values - if any - default to some standard values, unless they can be
64
* derived from the specified size.</li>
65
* <li>The other approach initializes a parameter generator object using
66
* algorithm-specific semantics, which are represented by a set of
67
* algorithm-specific parameter generation values. To generate Diffie-Hellman
68
* system parameters, for example, the parameter generation values usually
69
* consist of the size of the prime modulus and the size of the random
70
* exponent, both specified in number of bits.</li>
46
* <code>AlgorithmParameterGenerator</code> is used to generate algorithm
47
* parameters for specified algorithms.
73
49
* <p>In case the client does not explicitly initialize the
74
* <code>AlgorithmParameterGenerator</code> (via a call to an <code>init()</code>
75
* method), each provider must supply (and document) a default initialization.
76
* For example, the <b>GNU</b> provider uses a default modulus prime size of
77
* <code>1024</code> bits for the generation of <i>DSA</i> parameters.
50
* <code>AlgorithmParameterGenerator</code> (via a call to an
51
* <code>init()</code> method), each provider must supply (and document) a
52
* default initialization. For example, the <b>GNU</b> provider uses a default
53
* modulus prime size of <code>1024</code> bits for the generation of <i>DSA</i>
79
56
* @author Mark Benvenuto
92
69
private String algorithm;
95
* Creates an <code>AlgorithmParameterGenerator</code> object.
97
* @param paramGenSpi the delegate.
98
* @param provider the provider.
99
* @param algorithm the algorithm.
72
* Constructs a new instance of <code>AlgorithmParameterGenerator</code>.
75
* the generator to use.
77
* the provider to use.
79
* the algorithm to use.
101
81
protected AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi
102
82
paramGenSpi, Provider provider,
107
87
this.algorithm = algorithm;
111
* Returns the standard name of the algorithm this parameter generator is
114
* @return the string name of the algorithm.
90
/** @return the name of the algorithm. */
116
91
public final String getAlgorithm()
122
* Generates an <code>AlgorithmParameterGenerator</code> object that
123
* implements the specified digest algorithm. If the default provider package
124
* provides an implementation of the requested digest algorithm, an instance
125
* of <code>AlgorithmParameterGenerator</code> containing that implementation
126
* is returned. If the algorithm is not available in the default package,
127
* other packages are searched.
129
* @param algorithm the string name of the algorithm this parameter generator
130
* is associated with.
131
* @return the new <code>AlgorithmParameterGenerator</code> object.
132
* @throws NoSuchAlgorithmException if the algorithm is not available in the
97
* Returns a new <code>AlgorithmParameterGenerator</code> instance which
98
* generates algorithm parameters for the specified algorithm.
101
* the name of algorithm to use.
102
* @return the new instance.
103
* @throws NoSuchAlgorithmException
104
* if <code>algorithm</code> is not implemented by any provider.
135
106
public static AlgorithmParameterGenerator getInstance(String algorithm)
136
107
throws NoSuchAlgorithmException
153
* Generates an <code>AlgorithmParameterGenerator</code> object for the
154
* requested algorithm, as supplied from the specified provider, if such a
155
* parameter generator is available from the provider.
157
* @param algorithm the string name of the algorithm.
158
* @param provider the string name of the provider.
159
* @return the new <code>AlgorithmParameterGenerator</code> object.
160
* @throws NoSuchAlgorithmException if the <code>algorithm</code> is not
161
* available from the <code>provider</code>.
162
* @throws NoSuchProviderException if the <code>provider</code> is not
163
* available in the environment.
164
* @throws IllegalArgumentException if the <code>provider</code> name is
165
* <code>null</code> or empty.
124
* Returns a new <code>AlgorithmParameterGenerator</code> instance which
125
* generates algorithm parameters for the specified algorithm.
128
* the name of algorithm to use.
130
* the name of the {@link Provider} to use.
131
* @return the new instance.
132
* @throws NoSuchAlgorithmException
133
* if the algorithm is not implemented by the named provider.
134
* @throws NoSuchProviderException
135
* if the named provider was not found.
168
137
public static AlgorithmParameterGenerator getInstance(String algorithm,
183
* Generates an AlgorithmParameterGenerator object for the requested
184
* algorithm, as supplied from the specified provider, if such a parameter
185
* generator is available from the provider. Note: the <code>provider</code>
186
* doesn't have to be registered.
188
* @param algorithm the string name of the algorithm.
189
* @param provider the provider.
190
* @return the new AlgorithmParameterGenerator object.
191
* @throws NoSuchAlgorithmException if the algorithm is not available from
193
* @throws IllegalArgumentException if the provider is null.
152
* Returns a new <code>AlgorithmParameterGenerator</code> instance which
153
* generates algorithm parameters for the specified algorithm.
156
* the name of algorithm to use.
158
* the {@link Provider} to use.
159
* @return the new instance.
160
* @throws NoSuchAlgorithmException
161
* if the algorithm is not implemented by {@link Provider}.
222
* Returns the provider of this algorithm parameter generator object.
224
* @return the provider of this algorithm parameter generator object.
189
/** @return the {@link Provider} of this generator. */
226
190
public final Provider getProvider()
232
* Initializes this parameter generator for a certain <i>size</i>. To create
233
* the parameters, the {@link SecureRandom} implementation of the
234
* highest-priority installed provider is used as the source of randomness.
235
* (If none of the installed providers supply an implementation of
236
* {@link SecureRandom}, a system-provided source of randomness is used.)
238
* @param size the size (number of bits).
196
* Initializes this instance with the specified size. Since no source of
197
* randomness is supplied, a default one will be used.
200
* size (in bits) to use.
240
202
public final void init(int size)
246
* Initializes this parameter generator for a certain size and source of
208
* Initializes this instance with the specified key-size and source of
249
* @param size the size (number of bits).
250
* @param random the source of randomness.
212
* the size (in bits) to use.
214
* the {@link SecureRandom} to use.
252
216
public final void init(int size, SecureRandom random)
258
* Initializes this parameter generator with a set of algorithm-specific
259
* parameter generation values. To generate the parameters, the {@link
260
* SecureRandom} implementation of the highest-priority installed provider is
261
* used as the source of randomness. (If none of the installed providers
262
* supply an implementation of {@link SecureRandom}, a system-provided source
263
* of randomness is used.)
265
* @param genParamSpec the set of algorithm-specific parameter generation
267
* @throws InvalidAlgorithmParameterException if the given parameter
268
* generation values are inappropriate for this parameter generator.
222
* Initializes this instance with the specified {@link AlgorithmParameterSpec}.
223
* Since no source of randomness is supplied, a default one will be used.
225
* @param genParamSpec
226
* the {@link AlgorithmParameterSpec} to use.
227
* @throws InvalidAlgorithmParameterException
228
* if <code>genParamSpec</code> is invalid.
270
230
public final void init(AlgorithmParameterSpec genParamSpec)
271
throws InvalidAlgorithmParameterException
231
throws InvalidAlgorithmParameterException
273
233
init(genParamSpec, new SecureRandom());
277
* Initializes this parameter generator with a set of algorithm-specific
278
* parameter generation values.
280
* @param genParamSpec the set of algorithm-specific parameter generation
282
* @param random the source of randomness.
283
* @throws InvalidAlgorithmParameterException if the given parameter
284
* generation values are inappropriate for this parameter generator.
237
* Initializes this instance with the specified {@link AlgorithmParameterSpec}
238
* and source of randomness.
240
* @param genParamSpec
241
* the {@link AlgorithmParameterSpec} to use.
243
* the {@link SecureRandom} to use.
244
* @throws InvalidAlgorithmParameterException
245
* if <code>genParamSpec</code> is invalid.
286
247
public final void init(AlgorithmParameterSpec genParamSpec,
287
248
SecureRandom random)
290
251
paramGenSpi.engineInit(genParamSpec, random);
294
* Generates the parameters.
296
* @return the new {@link AlgorithmParameters} object.
254
/** @return a new instance of {@link AlgorithmParameters}. */
298
255
public final AlgorithmParameters generateParameters()
300
257
return paramGenSpi.engineGenerateParameters();