196 * SignatureSpi implementation from the first
197 * Provider that supports the specified algorithm is returned.
198 *
199 * <p> Note that the list of registered providers may be retrieved via
200 * the {@link Security#getProviders() Security.getProviders()} method.
201 *
202 * @implNote
203 * The JDK Reference Implementation additionally uses the
204 * {@code jdk.security.provider.preferred}
205 * {@link Security#getProperty(String) Security} property to determine
206 * the preferred provider order for the specified algorithm. This
207 * may be different than the order of providers returned by
208 * {@link Security#getProviders() Security.getProviders()}.
209 *
210 * @param algorithm the standard name of the algorithm requested.
211 * See the Signature section in the <a href=
212 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
213 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
214 * for information about standard algorithm names.
215 *
216 * @return the new Signature object.
217 *
218 * @exception NoSuchAlgorithmException if no Provider supports a
219 * Signature implementation for the
220 * specified algorithm.
221 *
222 * @see Provider
223 */
224 public static Signature getInstance(String algorithm)
225 throws NoSuchAlgorithmException {
226 List<Service> list;
227 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
228 list = GetInstance.getServices(rsaIds);
229 } else {
230 list = GetInstance.getServices("Signature", algorithm);
231 }
232 Iterator<Service> t = list.iterator();
233 if (t.hasNext() == false) {
234 throw new NoSuchAlgorithmException
235 (algorithm + " Signature not available");
236 }
237 // try services until we find an Spi or a working Signature subclass
238 NoSuchAlgorithmException failure;
239 do {
240 Service s = t.next();
241 if (isSpi(s)) {
242 return new Delegate(s, t, algorithm);
243 } else {
244 // must be a subclass of Signature, disable dynamic selection
245 try {
318 /**
319 * Returns a Signature object that implements the specified signature
320 * algorithm.
321 *
322 * <p> A new Signature object encapsulating the
323 * SignatureSpi implementation from the specified provider
324 * is returned. The specified provider must be registered
325 * in the security provider list.
326 *
327 * <p> Note that the list of registered providers may be retrieved via
328 * the {@link Security#getProviders() Security.getProviders()} method.
329 *
330 * @param algorithm the name of the algorithm requested.
331 * See the Signature section in the <a href=
332 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
333 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
334 * for information about standard algorithm names.
335 *
336 * @param provider the name of the provider.
337 *
338 * @return the new Signature object.
339 *
340 * @exception NoSuchAlgorithmException if a SignatureSpi
341 * implementation for the specified algorithm is not
342 * available from the specified provider.
343 *
344 * @exception NoSuchProviderException if the specified provider is not
345 * registered in the security provider list.
346 *
347 * @exception IllegalArgumentException if the provider name is null
348 * or empty.
349 *
350 * @see Provider
351 */
352 public static Signature getInstance(String algorithm, String provider)
353 throws NoSuchAlgorithmException, NoSuchProviderException {
354 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
355 // exception compatibility with existing code
356 if ((provider == null) || (provider.length() == 0)) {
357 throw new IllegalArgumentException("missing provider");
358 }
359 Provider p = Security.getProvider(provider);
360 if (p == null) {
361 throw new NoSuchProviderException
362 ("no such provider: " + provider);
363 }
364 return getInstanceRSA(p);
365 }
366 Instance instance = GetInstance.getInstance
367 ("Signature", SignatureSpi.class, algorithm, provider);
368 return getInstance(instance, algorithm);
369 }
370
371 /**
372 * Returns a Signature object that implements the specified
373 * signature algorithm.
374 *
375 * <p> A new Signature object encapsulating the
376 * SignatureSpi implementation from the specified Provider
377 * object is returned. Note that the specified Provider object
378 * does not have to be registered in the provider list.
379 *
380 * @param algorithm the name of the algorithm requested.
381 * See the Signature section in the <a href=
382 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
383 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
384 * for information about standard algorithm names.
385 *
386 * @param provider the provider.
387 *
388 * @return the new Signature object.
389 *
390 * @exception NoSuchAlgorithmException if a SignatureSpi
391 * implementation for the specified algorithm is not available
392 * from the specified Provider object.
393 *
394 * @exception IllegalArgumentException if the provider is null.
395 *
396 * @see Provider
397 *
398 * @since 1.4
399 */
400 public static Signature getInstance(String algorithm, Provider provider)
401 throws NoSuchAlgorithmException {
402 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
403 // exception compatibility with existing code
404 if (provider == null) {
405 throw new IllegalArgumentException("missing provider");
406 }
407 return getInstanceRSA(provider);
408 }
409 Instance instance = GetInstance.getInstance
410 ("Signature", SignatureSpi.class, algorithm, provider);
411 return getInstance(instance, algorithm);
412 }
413
414 // return an implementation for NONEwithRSA, which is a special case
415 // because of the Cipher.RSA/ECB/PKCS1Padding compatibility wrapper
416 private static Signature getInstanceRSA(Provider p)
417 throws NoSuchAlgorithmException {
418 // try Signature first
419 Service s = p.getService("Signature", RSA_SIGNATURE);
420 if (s != null) {
421 Instance instance = GetInstance.getInstance(s, SignatureSpi.class);
|
196 * SignatureSpi implementation from the first
197 * Provider that supports the specified algorithm is returned.
198 *
199 * <p> Note that the list of registered providers may be retrieved via
200 * the {@link Security#getProviders() Security.getProviders()} method.
201 *
202 * @implNote
203 * The JDK Reference Implementation additionally uses the
204 * {@code jdk.security.provider.preferred}
205 * {@link Security#getProperty(String) Security} property to determine
206 * the preferred provider order for the specified algorithm. This
207 * may be different than the order of providers returned by
208 * {@link Security#getProviders() Security.getProviders()}.
209 *
210 * @param algorithm the standard name of the algorithm requested.
211 * See the Signature section in the <a href=
212 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
213 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
214 * for information about standard algorithm names.
215 *
216 * @return the new {@code Signature} object
217 *
218 * @throws NoSuchAlgorithmException if no {@code Provider} supports a
219 * {@code Signature} implementation for the
220 * specified algorithm
221 *
222 * @throws NullPointerException if {@code algorithm} is {@code null}
223 *
224 * @see Provider
225 */
226 public static Signature getInstance(String algorithm)
227 throws NoSuchAlgorithmException {
228 Objects.requireNonNull(algorithm, "null algorithm name");
229 List<Service> list;
230 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
231 list = GetInstance.getServices(rsaIds);
232 } else {
233 list = GetInstance.getServices("Signature", algorithm);
234 }
235 Iterator<Service> t = list.iterator();
236 if (t.hasNext() == false) {
237 throw new NoSuchAlgorithmException
238 (algorithm + " Signature not available");
239 }
240 // try services until we find an Spi or a working Signature subclass
241 NoSuchAlgorithmException failure;
242 do {
243 Service s = t.next();
244 if (isSpi(s)) {
245 return new Delegate(s, t, algorithm);
246 } else {
247 // must be a subclass of Signature, disable dynamic selection
248 try {
321 /**
322 * Returns a Signature object that implements the specified signature
323 * algorithm.
324 *
325 * <p> A new Signature object encapsulating the
326 * SignatureSpi implementation from the specified provider
327 * is returned. The specified provider must be registered
328 * in the security provider list.
329 *
330 * <p> Note that the list of registered providers may be retrieved via
331 * the {@link Security#getProviders() Security.getProviders()} method.
332 *
333 * @param algorithm the name of the algorithm requested.
334 * See the Signature section in the <a href=
335 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
336 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
337 * for information about standard algorithm names.
338 *
339 * @param provider the name of the provider.
340 *
341 * @return the new {@code Signature} object
342 *
343 * @throws IllegalArgumentException if the provider name is {@code null}
344 * or empty
345 *
346 * @throws NoSuchAlgorithmException if a {@code SignatureSpi}
347 * implementation for the specified algorithm is not
348 * available from the specified provider
349 *
350 * @throws NoSuchProviderException if the specified provider is not
351 * registered in the security provider list
352 *
353 * @throws NullPointerException if {@code algorithm} is {@code null}
354 *
355 * @see Provider
356 */
357 public static Signature getInstance(String algorithm, String provider)
358 throws NoSuchAlgorithmException, NoSuchProviderException {
359 Objects.requireNonNull(algorithm, "null algorithm name");
360 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
361 // exception compatibility with existing code
362 if ((provider == null) || (provider.length() == 0)) {
363 throw new IllegalArgumentException("missing provider");
364 }
365 Provider p = Security.getProvider(provider);
366 if (p == null) {
367 throw new NoSuchProviderException
368 ("no such provider: " + provider);
369 }
370 return getInstanceRSA(p);
371 }
372 Instance instance = GetInstance.getInstance
373 ("Signature", SignatureSpi.class, algorithm, provider);
374 return getInstance(instance, algorithm);
375 }
376
377 /**
378 * Returns a Signature object that implements the specified
379 * signature algorithm.
380 *
381 * <p> A new Signature object encapsulating the
382 * SignatureSpi implementation from the specified Provider
383 * object is returned. Note that the specified Provider object
384 * does not have to be registered in the provider list.
385 *
386 * @param algorithm the name of the algorithm requested.
387 * See the Signature section in the <a href=
388 * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
389 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
390 * for information about standard algorithm names.
391 *
392 * @param provider the provider.
393 *
394 * @return the new {@code Signature} object
395 *
396 * @throws IllegalArgumentException if the provider is {@code null}
397 *
398 * @throws NoSuchAlgorithmException if a {@code SignatureSpi}
399 * implementation for the specified algorithm is not available
400 * from the specified {@code Provider} object
401 *
402 * @throws NullPointerException if {@code algorithm} is {@code null}
403 *
404 * @see Provider
405 *
406 * @since 1.4
407 */
408 public static Signature getInstance(String algorithm, Provider provider)
409 throws NoSuchAlgorithmException {
410 Objects.requireNonNull(algorithm, "null algorithm name");
411 if (algorithm.equalsIgnoreCase(RSA_SIGNATURE)) {
412 // exception compatibility with existing code
413 if (provider == null) {
414 throw new IllegalArgumentException("missing provider");
415 }
416 return getInstanceRSA(provider);
417 }
418 Instance instance = GetInstance.getInstance
419 ("Signature", SignatureSpi.class, algorithm, provider);
420 return getInstance(instance, algorithm);
421 }
422
423 // return an implementation for NONEwithRSA, which is a special case
424 // because of the Cipher.RSA/ECB/PKCS1Padding compatibility wrapper
425 private static Signature getInstanceRSA(Provider p)
426 throws NoSuchAlgorithmException {
427 // try Signature first
428 Service s = p.getService("Signature", RSA_SIGNATURE);
429 if (s != null) {
430 Instance instance = GetInstance.getInstance(s, SignatureSpi.class);
|