192 * KeyPairGeneratorSpi implementation from the first
193 * Provider that supports the specified algorithm is returned.
194 *
195 * <p> Note that the list of registered providers may be retrieved via
196 * the {@link Security#getProviders() Security.getProviders()} method.
197 *
198 * @implNote
199 * The JDK Reference Implementation additionally uses the
200 * {@code jdk.security.provider.preferred}
201 * {@link Security#getProperty(String) Security} property to determine
202 * the preferred provider order for the specified algorithm. This
203 * may be different than the order of providers returned by
204 * {@link Security#getProviders() Security.getProviders()}.
205 *
206 * @param algorithm the standard string name of the algorithm.
207 * See the KeyPairGenerator section in the <a href=
208 * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
209 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
210 * for information about standard algorithm names.
211 *
212 * @return the new KeyPairGenerator object.
213 *
214 * @exception NoSuchAlgorithmException if no Provider supports a
215 * KeyPairGeneratorSpi implementation for the
216 * specified algorithm.
217 *
218 * @see Provider
219 */
220 public static KeyPairGenerator getInstance(String algorithm)
221 throws NoSuchAlgorithmException {
222 List<Service> list =
223 GetInstance.getServices("KeyPairGenerator", algorithm);
224 Iterator<Service> t = list.iterator();
225 if (t.hasNext() == false) {
226 throw new NoSuchAlgorithmException
227 (algorithm + " KeyPairGenerator not available");
228 }
229 // find a working Spi or KeyPairGenerator subclass
230 NoSuchAlgorithmException failure = null;
231 do {
232 Service s = t.next();
233 try {
234 Instance instance =
235 GetInstance.getInstance(s, KeyPairGeneratorSpi.class);
236 if (instance.impl instanceof KeyPairGenerator) {
237 return getInstance(instance, algorithm);
238 } else {
239 return new Delegate(instance, t, algorithm);
240 }
241 } catch (NoSuchAlgorithmException e) {
250 /**
251 * Returns a KeyPairGenerator object that generates public/private
252 * key pairs for the specified algorithm.
253 *
254 * <p> A new KeyPairGenerator object encapsulating the
255 * KeyPairGeneratorSpi implementation from the specified provider
256 * is returned. The specified provider must be registered
257 * in the security provider list.
258 *
259 * <p> Note that the list of registered providers may be retrieved via
260 * the {@link Security#getProviders() Security.getProviders()} method.
261 *
262 * @param algorithm the standard string name of the algorithm.
263 * See the KeyPairGenerator section in the <a href=
264 * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
265 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
266 * for information about standard algorithm names.
267 *
268 * @param provider the string name of the provider.
269 *
270 * @return the new KeyPairGenerator object.
271 *
272 * @exception NoSuchAlgorithmException if a KeyPairGeneratorSpi
273 * implementation for the specified algorithm is not
274 * available from the specified provider.
275 *
276 * @exception NoSuchProviderException if the specified provider is not
277 * registered in the security provider list.
278 *
279 * @exception IllegalArgumentException if the provider name is null
280 * or empty.
281 *
282 * @see Provider
283 */
284 public static KeyPairGenerator getInstance(String algorithm,
285 String provider)
286 throws NoSuchAlgorithmException, NoSuchProviderException {
287 Instance instance = GetInstance.getInstance("KeyPairGenerator",
288 KeyPairGeneratorSpi.class, algorithm, provider);
289 return getInstance(instance, algorithm);
290 }
291
292 /**
293 * Returns a KeyPairGenerator object that generates public/private
294 * key pairs for the specified algorithm.
295 *
296 * <p> A new KeyPairGenerator object encapsulating the
297 * KeyPairGeneratorSpi implementation from the specified Provider
298 * object is returned. Note that the specified Provider object
299 * does not have to be registered in the provider list.
300 *
301 * @param algorithm the standard string name of the algorithm.
302 * See the KeyPairGenerator section in the <a href=
303 * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
304 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
305 * for information about standard algorithm names.
306 *
307 * @param provider the provider.
308 *
309 * @return the new KeyPairGenerator object.
310 *
311 * @exception NoSuchAlgorithmException if a KeyPairGeneratorSpi
312 * implementation for the specified algorithm is not available
313 * from the specified Provider object.
314 *
315 * @exception IllegalArgumentException if the specified provider is null.
316 *
317 * @see Provider
318 *
319 * @since 1.4
320 */
321 public static KeyPairGenerator getInstance(String algorithm,
322 Provider provider) throws NoSuchAlgorithmException {
323 Instance instance = GetInstance.getInstance("KeyPairGenerator",
324 KeyPairGeneratorSpi.class, algorithm, provider);
325 return getInstance(instance, algorithm);
326 }
327
328 /**
329 * Returns the provider of this key pair generator object.
330 *
331 * @return the provider of this key pair generator object
332 */
333 public final Provider getProvider() {
334 disableFailover();
335 return this.provider;
336 }
337
338 void disableFailover() {
339 // empty, overridden in Delegate
340 }
341
342 /**
|
192 * KeyPairGeneratorSpi implementation from the first
193 * Provider that supports the specified algorithm is returned.
194 *
195 * <p> Note that the list of registered providers may be retrieved via
196 * the {@link Security#getProviders() Security.getProviders()} method.
197 *
198 * @implNote
199 * The JDK Reference Implementation additionally uses the
200 * {@code jdk.security.provider.preferred}
201 * {@link Security#getProperty(String) Security} property to determine
202 * the preferred provider order for the specified algorithm. This
203 * may be different than the order of providers returned by
204 * {@link Security#getProviders() Security.getProviders()}.
205 *
206 * @param algorithm the standard string name of the algorithm.
207 * See the KeyPairGenerator section in the <a href=
208 * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
209 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
210 * for information about standard algorithm names.
211 *
212 * @return the new {@code KeyPairGenerator} object
213 *
214 * @throws NoSuchAlgorithmException if no {@code Provider} supports a
215 * {@code KeyPairGeneratorSpi} implementation for the
216 * specified algorithm
217 *
218 * @throws NullPointerException if {@code algorithm} is {@code null}
219 *
220 * @see Provider
221 */
222 public static KeyPairGenerator getInstance(String algorithm)
223 throws NoSuchAlgorithmException {
224 Objects.requireNonNull(algorithm, "null algorithm name");
225 List<Service> list =
226 GetInstance.getServices("KeyPairGenerator", algorithm);
227 Iterator<Service> t = list.iterator();
228 if (t.hasNext() == false) {
229 throw new NoSuchAlgorithmException
230 (algorithm + " KeyPairGenerator not available");
231 }
232 // find a working Spi or KeyPairGenerator subclass
233 NoSuchAlgorithmException failure = null;
234 do {
235 Service s = t.next();
236 try {
237 Instance instance =
238 GetInstance.getInstance(s, KeyPairGeneratorSpi.class);
239 if (instance.impl instanceof KeyPairGenerator) {
240 return getInstance(instance, algorithm);
241 } else {
242 return new Delegate(instance, t, algorithm);
243 }
244 } catch (NoSuchAlgorithmException e) {
253 /**
254 * Returns a KeyPairGenerator object that generates public/private
255 * key pairs for the specified algorithm.
256 *
257 * <p> A new KeyPairGenerator object encapsulating the
258 * KeyPairGeneratorSpi implementation from the specified provider
259 * is returned. The specified provider must be registered
260 * in the security provider list.
261 *
262 * <p> Note that the list of registered providers may be retrieved via
263 * the {@link Security#getProviders() Security.getProviders()} method.
264 *
265 * @param algorithm the standard string name of the algorithm.
266 * See the KeyPairGenerator section in the <a href=
267 * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
268 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
269 * for information about standard algorithm names.
270 *
271 * @param provider the string name of the provider.
272 *
273 * @return the new {@code KeyPairGenerator} object
274 *
275 * @throws IllegalArgumentException if the provider name is {@code null}
276 * or empty
277 *
278 * @throws NoSuchAlgorithmException if a {@code KeyPairGeneratorSpi}
279 * implementation for the specified algorithm is not
280 * available from the specified provider
281 *
282 * @throws NoSuchProviderException if the specified provider is not
283 * registered in the security provider list
284 *
285 * @throws NullPointerException if {@code algorithm} is {@code null}
286 *
287 * @see Provider
288 */
289 public static KeyPairGenerator getInstance(String algorithm,
290 String provider)
291 throws NoSuchAlgorithmException, NoSuchProviderException {
292 Objects.requireNonNull(algorithm, "null algorithm name");
293 Instance instance = GetInstance.getInstance("KeyPairGenerator",
294 KeyPairGeneratorSpi.class, algorithm, provider);
295 return getInstance(instance, algorithm);
296 }
297
298 /**
299 * Returns a KeyPairGenerator object that generates public/private
300 * key pairs for the specified algorithm.
301 *
302 * <p> A new KeyPairGenerator object encapsulating the
303 * KeyPairGeneratorSpi implementation from the specified Provider
304 * object is returned. Note that the specified Provider object
305 * does not have to be registered in the provider list.
306 *
307 * @param algorithm the standard string name of the algorithm.
308 * See the KeyPairGenerator section in the <a href=
309 * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyPairGenerator">
310 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
311 * for information about standard algorithm names.
312 *
313 * @param provider the provider.
314 *
315 * @return the new {@code KeyPairGenerator} object
316 *
317 * @throws IllegalArgumentException if the specified provider is
318 * {@code null}
319 *
320 * @throws NoSuchAlgorithmException if a {@code KeyPairGeneratorSpi}
321 * implementation for the specified algorithm is not available
322 * from the specified {@code Provider} object
323 *
324 * @throws NullPointerException if {@code algorithm} is {@code null}
325 *
326 * @see Provider
327 *
328 * @since 1.4
329 */
330 public static KeyPairGenerator getInstance(String algorithm,
331 Provider provider) throws NoSuchAlgorithmException {
332 Objects.requireNonNull(algorithm, "null algorithm name");
333 Instance instance = GetInstance.getInstance("KeyPairGenerator",
334 KeyPairGeneratorSpi.class, algorithm, provider);
335 return getInstance(instance, algorithm);
336 }
337
338 /**
339 * Returns the provider of this key pair generator object.
340 *
341 * @return the provider of this key pair generator object
342 */
343 public final Provider getProvider() {
344 disableFailover();
345 return this.provider;
346 }
347
348 void disableFailover() {
349 // empty, overridden in Delegate
350 }
351
352 /**
|