~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to java/security/AlgorithmParameterGenerator.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
import java.security.spec.AlgorithmParameterSpec;
44
44
 
45
45
/**
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>
50
 
 *
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>
54
 
 *
55
 
 * <ul>
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>
71
 
 * </ul>
72
 
 *
 
46
 * <code>AlgorithmParameterGenerator</code> is used to generate algorithm
 
47
 * parameters for specified algorithms.
 
48
 * 
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>
 
54
 * parameters.
78
55
 *
79
56
 * @author Mark Benvenuto
80
57
 * @since 1.2
92
69
  private String algorithm;
93
70
 
94
71
  /**
95
 
   * Creates an <code>AlgorithmParameterGenerator</code> object.
96
 
   *
97
 
   * @param paramGenSpi the delegate.
98
 
   * @param provider the provider.
99
 
   * @param algorithm the algorithm.
 
72
   * Constructs a new instance of <code>AlgorithmParameterGenerator</code>.
 
73
   * 
 
74
   * @param paramGenSpi
 
75
   *          the generator to use.
 
76
   * @param provider
 
77
   *          the provider to use.
 
78
   * @param algorithm
 
79
   *          the algorithm to use.
100
80
   */
101
81
  protected AlgorithmParameterGenerator(AlgorithmParameterGeneratorSpi
102
82
                                        paramGenSpi, Provider provider,
107
87
    this.algorithm = algorithm;
108
88
  }
109
89
 
110
 
  /**
111
 
   * Returns the standard name of the algorithm this parameter generator is
112
 
   * associated with.
113
 
   *
114
 
   * @return the string name of the algorithm.
115
 
   */
 
90
  /** @return the name of the algorithm. */
116
91
  public final String getAlgorithm()
117
92
  {
118
93
    return algorithm;
119
94
  }
120
95
 
121
96
  /**
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.
128
 
   *
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
133
 
   * environment.
 
97
   * Returns a new <code>AlgorithmParameterGenerator</code> instance which
 
98
   * generates algorithm parameters for the specified algorithm.
 
99
   * 
 
100
   * @param 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.
134
105
   */
135
106
  public static AlgorithmParameterGenerator getInstance(String algorithm)
136
107
    throws NoSuchAlgorithmException
150
121
  }
151
122
 
152
123
  /**
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.
156
 
   *
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.
166
 
   * @see Provider
 
124
   * Returns a new <code>AlgorithmParameterGenerator</code> instance which
 
125
   * generates algorithm parameters for the specified algorithm.
 
126
   * 
 
127
   * @param algorithm
 
128
   *          the name of algorithm to use.
 
129
   * @param provider
 
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.
167
136
   */
168
137
  public static AlgorithmParameterGenerator getInstance(String algorithm,
169
138
                                                        String provider)
180
149
  }
181
150
 
182
151
  /**
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.
187
 
   *
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
192
 
   * the provider.
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.
 
154
   * 
 
155
   * @param algorithm
 
156
   *          the name of algorithm to use.
 
157
   * @param provider
 
158
   *          the {@link Provider} to use.
 
159
   * @return the new instance.
 
160
   * @throws NoSuchAlgorithmException
 
161
   *           if the algorithm is not implemented by {@link Provider}.
194
162
   * @since 1.4
195
163
   * @see Provider
196
164
   */
218
186
      }
219
187
  }
220
188
 
221
 
  /**
222
 
   * Returns the provider of this algorithm parameter generator object.
223
 
   *
224
 
   * @return the provider of this algorithm parameter generator object.
225
 
   */
 
189
  /** @return the {@link Provider} of this generator. */
226
190
  public final Provider getProvider()
227
191
  {
228
192
    return provider;
229
193
  }
230
194
 
231
195
  /**
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.)
237
 
   *
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.
 
198
   * 
 
199
   * @param size
 
200
   *          size (in bits) to use.
239
201
   */
240
202
  public final void init(int size)
241
203
  {
243
205
  }
244
206
 
245
207
  /**
246
 
   * Initializes this parameter generator for a certain size and source of
 
208
   * Initializes this instance with the specified key-size and source of
247
209
   * randomness.
248
 
   *
249
 
   * @param size the size (number of bits).
250
 
   * @param random the source of randomness.
 
210
   * 
 
211
   * @param size
 
212
   *          the size (in bits) to use.
 
213
   * @param random
 
214
   *          the {@link SecureRandom} to use.
251
215
   */
252
216
  public final void init(int size, SecureRandom random)
253
217
  {
255
219
  }
256
220
 
257
221
  /**
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.)
264
 
   *
265
 
   * @param genParamSpec the set of algorithm-specific parameter generation
266
 
   * values.
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.
 
224
   * 
 
225
   * @param genParamSpec
 
226
   *          the {@link AlgorithmParameterSpec} to use.
 
227
   * @throws InvalidAlgorithmParameterException
 
228
   *           if <code>genParamSpec</code> is invalid.
269
229
   */
270
230
  public final void init(AlgorithmParameterSpec genParamSpec)
271
 
    throws InvalidAlgorithmParameterException
 
231
      throws InvalidAlgorithmParameterException
272
232
  {
273
233
    init(genParamSpec, new SecureRandom());
274
234
  }
275
235
 
276
236
  /**
277
 
   * Initializes this parameter generator with a set of algorithm-specific
278
 
   * parameter generation values.
279
 
   *
280
 
   * @param genParamSpec the set of algorithm-specific parameter generation
281
 
   * values.
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.
 
239
   * 
 
240
   * @param genParamSpec
 
241
   *          the {@link AlgorithmParameterSpec} to use.
 
242
   * @param random
 
243
   *          the {@link SecureRandom} to use.
 
244
   * @throws InvalidAlgorithmParameterException
 
245
   *           if <code>genParamSpec</code> is invalid.
285
246
   */
286
247
  public final void init(AlgorithmParameterSpec genParamSpec,
287
248
                         SecureRandom random)
290
251
    paramGenSpi.engineInit(genParamSpec, random);
291
252
  }
292
253
 
293
 
  /**
294
 
   * Generates the parameters.
295
 
   *
296
 
   * @return the new {@link AlgorithmParameters} object.
297
 
   */
 
254
  /** @return a new instance of {@link AlgorithmParameters}. */
298
255
  public final AlgorithmParameters generateParameters()
299
256
  {
300
257
    return paramGenSpi.engineGenerateParameters();