9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.security;
27
28 import java.security.spec.AlgorithmParameterSpec;
29
30 /**
31 * The {@code AlgorithmParameterGenerator} class is used to generate a
32 * set of
33 * parameters to be used with a certain algorithm. Parameter generators
34 * are constructed using the {@code getInstance} factory methods
35 * (static methods that return instances of a given class).
36 *
37 * <P>The object that will generate the parameters can be initialized
38 * in two different ways: in an algorithm-independent manner, or in an
39 * algorithm-specific manner:
40 *
41 * <ul>
42 * <li>The algorithm-independent approach uses the fact that all parameter
43 * generators share the concept of a "size" and a
44 * source of randomness. The measure of size is universally shared
45 * by all algorithm parameters, though it is interpreted differently
46 * for different algorithms. For example, in the case of parameters for
47 * the <i>DSA</i> algorithm, "size" corresponds to the size
48 * of the prime modulus (in bits).
136 * Provider that supports the specified algorithm is returned.
137 *
138 * <p> Note that the list of registered providers may be retrieved via
139 * the {@link Security#getProviders() Security.getProviders()} method.
140 *
141 * @implNote
142 * The JDK Reference Implementation additionally uses the
143 * {@code jdk.security.provider.preferred}
144 * {@link Security#getProperty(String) Security} property to determine
145 * the preferred provider order for the specified algorithm. This
146 * may be different than the order of providers returned by
147 * {@link Security#getProviders() Security.getProviders()}.
148 *
149 * @param algorithm the name of the algorithm this
150 * parameter generator is associated with.
151 * See the AlgorithmParameterGenerator section in the <a href=
152 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
153 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
154 * for information about standard algorithm names.
155 *
156 * @return the new AlgorithmParameterGenerator object.
157 *
158 * @exception NoSuchAlgorithmException if no Provider supports an
159 * AlgorithmParameterGeneratorSpi implementation for the
160 * specified algorithm.
161 *
162 * @see Provider
163 */
164 public static AlgorithmParameterGenerator getInstance(String algorithm)
165 throws NoSuchAlgorithmException {
166 try {
167 Object[] objs = Security.getImpl(algorithm,
168 "AlgorithmParameterGenerator",
169 (String)null);
170 return new AlgorithmParameterGenerator
171 ((AlgorithmParameterGeneratorSpi)objs[0],
172 (Provider)objs[1],
173 algorithm);
174 } catch(NoSuchProviderException e) {
175 throw new NoSuchAlgorithmException(algorithm + " not found");
176 }
177 }
178
179 /**
180 * Returns an AlgorithmParameterGenerator object for generating
181 * a set of parameters to be used with the specified algorithm.
182 *
183 * <p> A new AlgorithmParameterGenerator object encapsulating the
184 * AlgorithmParameterGeneratorSpi implementation from the specified provider
185 * is returned. The specified provider must be registered
186 * in the security provider list.
187 *
188 * <p> Note that the list of registered providers may be retrieved via
189 * the {@link Security#getProviders() Security.getProviders()} method.
190 *
191 * @param algorithm the name of the algorithm this
192 * parameter generator is associated with.
193 * See the AlgorithmParameterGenerator section in the <a href=
194 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
195 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
196 * for information about standard algorithm names.
197 *
198 * @param provider the string name of the Provider.
199 *
200 * @return the new AlgorithmParameterGenerator object.
201 *
202 * @exception NoSuchAlgorithmException if an AlgorithmParameterGeneratorSpi
203 * implementation for the specified algorithm is not
204 * available from the specified provider.
205 *
206 * @exception NoSuchProviderException if the specified provider is not
207 * registered in the security provider list.
208 *
209 * @exception IllegalArgumentException if the provider name is null
210 * or empty.
211 *
212 * @see Provider
213 */
214 public static AlgorithmParameterGenerator getInstance(String algorithm,
215 String provider)
216 throws NoSuchAlgorithmException, NoSuchProviderException
217 {
218 if (provider == null || provider.length() == 0)
219 throw new IllegalArgumentException("missing provider");
220 Object[] objs = Security.getImpl(algorithm,
221 "AlgorithmParameterGenerator",
222 provider);
223 return new AlgorithmParameterGenerator
224 ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
225 algorithm);
226 }
227
228 /**
229 * Returns an AlgorithmParameterGenerator object for generating
230 * a set of parameters to be used with the specified algorithm.
231 *
232 * <p> A new AlgorithmParameterGenerator object encapsulating the
233 * AlgorithmParameterGeneratorSpi implementation from the specified Provider
234 * object is returned. Note that the specified Provider object
235 * does not have to be registered in the provider list.
236 *
237 * @param algorithm the string name of the algorithm this
238 * parameter generator is associated with.
239 * See the AlgorithmParameterGenerator section in the <a href=
240 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
241 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
242 * for information about standard algorithm names.
243 *
244 * @param provider the Provider object.
245 *
246 * @return the new AlgorithmParameterGenerator object.
247 *
248 * @exception NoSuchAlgorithmException if an AlgorithmParameterGeneratorSpi
249 * implementation for the specified algorithm is not available
250 * from the specified Provider object.
251 *
252 * @exception IllegalArgumentException if the specified provider is null.
253 *
254 * @see Provider
255 *
256 * @since 1.4
257 */
258 public static AlgorithmParameterGenerator getInstance(String algorithm,
259 Provider provider)
260 throws NoSuchAlgorithmException
261 {
262 if (provider == null)
263 throw new IllegalArgumentException("missing provider");
264 Object[] objs = Security.getImpl(algorithm,
265 "AlgorithmParameterGenerator",
266 provider);
267 return new AlgorithmParameterGenerator
268 ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
269 algorithm);
270 }
271
272 /**
273 * Returns the provider of this algorithm parameter generator object.
274 *
275 * @return the provider of this algorithm parameter generator object
276 */
277 public final Provider getProvider() {
278 return this.provider;
279 }
280
281 /**
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.security;
27
28 import java.security.spec.AlgorithmParameterSpec;
29 import java.util.Objects;
30
31 /**
32 * The {@code AlgorithmParameterGenerator} class is used to generate a
33 * set of
34 * parameters to be used with a certain algorithm. Parameter generators
35 * are constructed using the {@code getInstance} factory methods
36 * (static methods that return instances of a given class).
37 *
38 * <P>The object that will generate the parameters can be initialized
39 * in two different ways: in an algorithm-independent manner, or in an
40 * algorithm-specific manner:
41 *
42 * <ul>
43 * <li>The algorithm-independent approach uses the fact that all parameter
44 * generators share the concept of a "size" and a
45 * source of randomness. The measure of size is universally shared
46 * by all algorithm parameters, though it is interpreted differently
47 * for different algorithms. For example, in the case of parameters for
48 * the <i>DSA</i> algorithm, "size" corresponds to the size
49 * of the prime modulus (in bits).
137 * Provider that supports the specified algorithm is returned.
138 *
139 * <p> Note that the list of registered providers may be retrieved via
140 * the {@link Security#getProviders() Security.getProviders()} method.
141 *
142 * @implNote
143 * The JDK Reference Implementation additionally uses the
144 * {@code jdk.security.provider.preferred}
145 * {@link Security#getProperty(String) Security} property to determine
146 * the preferred provider order for the specified algorithm. This
147 * may be different than the order of providers returned by
148 * {@link Security#getProviders() Security.getProviders()}.
149 *
150 * @param algorithm the name of the algorithm this
151 * parameter generator is associated with.
152 * See the AlgorithmParameterGenerator section in the <a href=
153 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
154 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
155 * for information about standard algorithm names.
156 *
157 * @return the new {@code AlgorithmParameterGenerator} object
158 *
159 * @throws NoSuchAlgorithmException if no {@code Provider} supports an
160 * {@code AlgorithmParameterGeneratorSpi} implementation for the
161 * specified algorithm
162 *
163 * @throws NullPointerException if {@code algorithm} is {@code null}
164 *
165 * @see Provider
166 */
167 public static AlgorithmParameterGenerator getInstance(String algorithm)
168 throws NoSuchAlgorithmException {
169 Objects.requireNonNull(algorithm, "null algorithm name");
170 try {
171 Object[] objs = Security.getImpl(algorithm,
172 "AlgorithmParameterGenerator",
173 (String)null);
174 return new AlgorithmParameterGenerator
175 ((AlgorithmParameterGeneratorSpi)objs[0],
176 (Provider)objs[1],
177 algorithm);
178 } catch(NoSuchProviderException e) {
179 throw new NoSuchAlgorithmException(algorithm + " not found");
180 }
181 }
182
183 /**
184 * Returns an AlgorithmParameterGenerator object for generating
185 * a set of parameters to be used with the specified algorithm.
186 *
187 * <p> A new AlgorithmParameterGenerator object encapsulating the
188 * AlgorithmParameterGeneratorSpi implementation from the specified provider
189 * is returned. The specified provider must be registered
190 * in the security provider list.
191 *
192 * <p> Note that the list of registered providers may be retrieved via
193 * the {@link Security#getProviders() Security.getProviders()} method.
194 *
195 * @param algorithm the name of the algorithm this
196 * parameter generator is associated with.
197 * See the AlgorithmParameterGenerator section in the <a href=
198 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
199 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
200 * for information about standard algorithm names.
201 *
202 * @param provider the string name of the Provider.
203 *
204 * @return the new {@code AlgorithmParameterGenerator} object
205 *
206 * @throws IllegalArgumentException if the provider name is {@code null}
207 * or empty
208 *
209 * @throws NoSuchAlgorithmException if an
210 * {@code AlgorithmParameterGeneratorSpi}
211 * implementation for the specified algorithm is not
212 * available from the specified provider
213 *
214 * @throws NoSuchProviderException if the specified provider is not
215 * registered in the security provider list
216 *
217 * @throws NullPointerException if {@code algorithm} is {@code null}
218 *
219 * @see Provider
220 */
221 public static AlgorithmParameterGenerator getInstance(String algorithm,
222 String provider)
223 throws NoSuchAlgorithmException, NoSuchProviderException
224 {
225 Objects.requireNonNull(algorithm, "null algorithm name");
226 if (provider == null || provider.length() == 0)
227 throw new IllegalArgumentException("missing provider");
228 Object[] objs = Security.getImpl(algorithm,
229 "AlgorithmParameterGenerator",
230 provider);
231 return new AlgorithmParameterGenerator
232 ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
233 algorithm);
234 }
235
236 /**
237 * Returns an AlgorithmParameterGenerator object for generating
238 * a set of parameters to be used with the specified algorithm.
239 *
240 * <p> A new AlgorithmParameterGenerator object encapsulating the
241 * AlgorithmParameterGeneratorSpi implementation from the specified Provider
242 * object is returned. Note that the specified Provider object
243 * does not have to be registered in the provider list.
244 *
245 * @param algorithm the string name of the algorithm this
246 * parameter generator is associated with.
247 * See the AlgorithmParameterGenerator section in the <a href=
248 * "{@docRoot}/../technotes/guides/security/StandardNames.html#AlgorithmParameterGenerator">
249 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
250 * for information about standard algorithm names.
251 *
252 * @param provider the {@code Provider} object.
253 *
254 * @return the new {@code AlgorithmParameterGenerator} object
255 *
256 * @throws IllegalArgumentException if the specified provider is
257 * {@code null}
258 *
259 * @throws NoSuchAlgorithmException if an
260 * {@code AlgorithmParameterGeneratorSpi}
261 * implementation for the specified algorithm is not available
262 * from the specified {@code Provider} object
263 *
264 * @throws NullPointerException if {@code algorithm} is {@code null}
265 *
266 * @see Provider
267 *
268 * @since 1.4
269 */
270 public static AlgorithmParameterGenerator getInstance(String algorithm,
271 Provider provider)
272 throws NoSuchAlgorithmException
273 {
274 Objects.requireNonNull(algorithm, "null algorithm name");
275 if (provider == null)
276 throw new IllegalArgumentException("missing provider");
277 Object[] objs = Security.getImpl(algorithm,
278 "AlgorithmParameterGenerator",
279 provider);
280 return new AlgorithmParameterGenerator
281 ((AlgorithmParameterGeneratorSpi)objs[0], (Provider)objs[1],
282 algorithm);
283 }
284
285 /**
286 * Returns the provider of this algorithm parameter generator object.
287 *
288 * @return the provider of this algorithm parameter generator object
289 */
290 public final Provider getProvider() {
291 return this.provider;
292 }
293
294 /**
|