< prev index next >

src/java.base/share/classes/java/security/SecureRandom.java

Print this page
rev 15967 : [mq]: GetInstance


 286      * {@code SecureRandomSpi} implementation from the first
 287      * Provider that supports the specified algorithm is returned.
 288      *
 289      * <p> Note that the list of registered providers may be retrieved via
 290      * the {@link Security#getProviders() Security.getProviders()} method.
 291      *
 292      * @implNote
 293      * The JDK Reference Implementation additionally uses the
 294      * {@code jdk.security.provider.preferred}
 295      * {@link Security#getProperty(String) Security} property to determine
 296      * the preferred provider order for the specified algorithm. This
 297      * may be different than the order of providers returned by
 298      * {@link Security#getProviders() Security.getProviders()}.
 299      *
 300      * @param algorithm the name of the RNG algorithm.
 301      * See the {@code SecureRandom} section in the <a href=
 302      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 303      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 304      * for information about standard RNG algorithm names.
 305      *
 306      * @return the new {@code SecureRandom} object.
 307      *
 308      * @exception NoSuchAlgorithmException if no Provider supports a
 309      *          {@code SecureRandomSpi} implementation for the
 310      *          specified algorithm.


 311      *
 312      * @see Provider
 313      *
 314      * @since 1.2
 315      */
 316     public static SecureRandom getInstance(String algorithm)
 317             throws NoSuchAlgorithmException {

 318         Instance instance = GetInstance.getInstance("SecureRandom",
 319                 SecureRandomSpi.class, algorithm);
 320         return new SecureRandom((SecureRandomSpi)instance.impl,
 321                 instance.provider, algorithm);
 322     }
 323 
 324     /**
 325      * Returns a {@code SecureRandom} object that implements the specified
 326      * Random Number Generator (RNG) algorithm.
 327      *
 328      * <p> A new {@code SecureRandom} object encapsulating the
 329      * {@code SecureRandomSpi} implementation from the specified provider
 330      * is returned.  The specified provider must be registered
 331      * in the security provider list.
 332      *
 333      * <p> Note that the list of registered providers may be retrieved via
 334      * the {@link Security#getProviders() Security.getProviders()} method.
 335      *
 336      * @param algorithm the name of the RNG algorithm.
 337      * See the {@code SecureRandom} section in the <a href=
 338      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 339      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 340      * for information about standard RNG algorithm names.
 341      *
 342      * @param provider the name of the provider.
 343      *
 344      * @return the new {@code SecureRandom} object.



 345      *
 346      * @throws NoSuchAlgorithmException if a {@code SecureRandomSpi}
 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 IllegalArgumentException if the provider name is null
 354      *         or empty.
 355      *
 356      * @see Provider
 357      *
 358      * @since 1.2
 359      */
 360     public static SecureRandom getInstance(String algorithm, String provider)
 361             throws NoSuchAlgorithmException, NoSuchProviderException {

 362         Instance instance = GetInstance.getInstance("SecureRandom",
 363             SecureRandomSpi.class, algorithm, provider);
 364         return new SecureRandom((SecureRandomSpi)instance.impl,
 365             instance.provider, algorithm);
 366     }
 367 
 368     /**
 369      * Returns a {@code SecureRandom} object that implements the specified
 370      * Random Number Generator (RNG) algorithm.
 371      *
 372      * <p> A new {@code SecureRandom} object encapsulating the
 373      * {@code SecureRandomSpi} implementation from the specified {@code Provider}
 374      * object is returned.  Note that the specified {@code Provider} object
 375      * does not have to be registered in the provider list.
 376      *
 377      * @param algorithm the name of the RNG algorithm.
 378      * See the {@code SecureRandom} section in the <a href=
 379      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 380      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 381      * for information about standard RNG algorithm names.
 382      *
 383      * @param provider the provider.
 384      *
 385      * @return the new {@code SecureRandom} object.



 386      *
 387      * @throws NoSuchAlgorithmException if a {@code SecureRandomSpi}
 388      *         implementation for the specified algorithm is not available
 389      *         from the specified {@code Provider} object.
 390      *
 391      * @throws IllegalArgumentException if the specified provider is null.
 392      *
 393      * @see Provider
 394      *
 395      * @since 1.4
 396      */
 397     public static SecureRandom getInstance(String algorithm,
 398             Provider provider) throws NoSuchAlgorithmException {

 399         Instance instance = GetInstance.getInstance("SecureRandom",
 400             SecureRandomSpi.class, algorithm, provider);
 401         return new SecureRandom((SecureRandomSpi)instance.impl,
 402             instance.provider, algorithm);
 403     }
 404 
 405     /**
 406      * Returns a {@code SecureRandom} object that implements the specified
 407      * Random Number Generator (RNG) algorithm and supports the specified
 408      * {@code SecureRandomParameters} request.
 409      *
 410      * <p> This method traverses the list of registered security Providers,
 411      * starting with the most preferred Provider.
 412      * A new {@code SecureRandom} object encapsulating the
 413      * {@code SecureRandomSpi} implementation from the first
 414      * Provider that supports the specified algorithm and the specified
 415      * {@code SecureRandomParameters} is returned.
 416      *
 417      * <p> Note that the list of registered providers may be retrieved via
 418      * the {@link Security#getProviders() Security.getProviders()} method.
 419      *
 420      * @implNote
 421      * The JDK Reference Implementation additionally uses the
 422      * {@code jdk.security.provider.preferred} property to determine
 423      * the preferred provider order for the specified algorithm. This
 424      * may be different than the order of providers returned by
 425      * {@link Security#getProviders() Security.getProviders()}.
 426      *
 427      * @param algorithm the name of the RNG algorithm.
 428      * See the {@code SecureRandom} section in the <a href=
 429      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 430      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 431      * for information about standard RNG algorithm names.
 432      *
 433      * @param params the {@code SecureRandomParameters}
 434      *               the newly created {@code SecureRandom} object must support.
 435      *
 436      * @return the new {@code SecureRandom} object.



 437      *
 438      * @throws NoSuchAlgorithmException if no Provider supports a
 439      *         {@code SecureRandomSpi} implementation for the specified
 440      *         algorithm and parameters.
 441      *
 442      * @throws IllegalArgumentException if the specified params is null.
 443      *
 444      * @see Provider
 445      *
 446      * @since 9
 447      */
 448     public static SecureRandom getInstance(
 449             String algorithm, SecureRandomParameters params)
 450             throws NoSuchAlgorithmException {

 451         if (params == null) {
 452             throw new IllegalArgumentException("params cannot be null");
 453         }
 454         Instance instance = GetInstance.getInstance("SecureRandom",
 455                 SecureRandomSpi.class, algorithm, params);
 456         return new SecureRandom((SecureRandomSpi)instance.impl,
 457                 instance.provider, algorithm);
 458     }
 459 
 460     /**
 461      * Returns a {@code SecureRandom} object that implements the specified
 462      * Random Number Generator (RNG) algorithm and supports the specified
 463      * {@code SecureRandomParameters} request.
 464      *
 465      * <p> A new {@code SecureRandom} object encapsulating the
 466      * {@code SecureRandomSpi} implementation from the specified provider
 467      * is returned.  The specified provider must be registered
 468      * in the security provider list.
 469      *
 470      * <p> Note that the list of registered providers may be retrieved via
 471      * the {@link Security#getProviders() Security.getProviders()} method.
 472      *
 473      * @param algorithm the name of the RNG algorithm.
 474      * See the {@code SecureRandom} section in the <a href=
 475      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 476      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 477      * for information about standard RNG algorithm names.
 478      *
 479      * @param params the {@code SecureRandomParameters}
 480      *               the newly created {@code SecureRandom} object must support.
 481      *
 482      * @param provider the name of the provider.
 483      *
 484      * @return the new {@code SecureRandom} object.



 485      *
 486      * @throws NoSuchAlgorithmException if the specified provider does not
 487      *         support a {@code SecureRandomSpi} implementation for the
 488      *         specified algorithm and parameters.
 489      *
 490      * @throws NoSuchProviderException if the specified provider is not
 491      *         registered in the security provider list.
 492      *
 493      * @throws IllegalArgumentException if the provider name is null
 494      *         or empty, or params is null.
 495      *
 496      * @see Provider
 497      *
 498      * @since 9
 499      */
 500     public static SecureRandom getInstance(String algorithm,
 501             SecureRandomParameters params, String provider)
 502             throws NoSuchAlgorithmException, NoSuchProviderException {

 503         if (params == null) {
 504             throw new IllegalArgumentException("params cannot be null");
 505         }
 506         Instance instance = GetInstance.getInstance("SecureRandom",
 507                 SecureRandomSpi.class, algorithm, params, provider);
 508         return new SecureRandom((SecureRandomSpi)instance.impl,
 509                 instance.provider, algorithm);
 510     }
 511 
 512     /**
 513      * Returns a {@code SecureRandom} object that implements the specified
 514      * Random Number Generator (RNG) algorithm and supports the specified
 515      * {@code SecureRandomParameters} request.
 516      *
 517      * <p> A new {@code SecureRandom} object encapsulating the
 518      * {@code SecureRandomSpi} implementation from the specified
 519      * {@code Provider} object is returned.  Note that the specified
 520      * {@code Provider} object does not have to be registered in the
 521      * provider list.
 522      *
 523      * @param algorithm the name of the RNG algorithm.
 524      * See the {@code SecureRandom} section in the <a href=
 525      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 526      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 527      * for information about standard RNG algorithm names.
 528      *
 529      * @param params the {@code SecureRandomParameters}
 530      *               the newly created {@code SecureRandom} object must support.
 531      *
 532      * @param provider the provider.
 533      *
 534      * @return the new {@code SecureRandom} object.



 535      *
 536      * @throws NoSuchAlgorithmException if the specified provider does not
 537      *         support a {@code SecureRandomSpi} implementation for the
 538      *         specified algorithm and parameters.
 539      *
 540      * @throws IllegalArgumentException if the specified provider or params
 541      *         is null.
 542      *
 543      * @see Provider
 544      *
 545      * @since 9
 546      */
 547     public static SecureRandom getInstance(String algorithm,
 548             SecureRandomParameters params, Provider provider)
 549             throws NoSuchAlgorithmException {

 550         if (params == null) {
 551             throw new IllegalArgumentException("params cannot be null");
 552         }
 553         Instance instance = GetInstance.getInstance("SecureRandom",
 554                 SecureRandomSpi.class, algorithm, params, provider);
 555         return new SecureRandom((SecureRandomSpi)instance.impl,
 556                 instance.provider, algorithm);
 557     }
 558 
 559     /**
 560      * Returns the {@code SecureRandomSpi} of this {@code SecureRandom} object.
 561      */
 562     SecureRandomSpi getSecureRandomSpi() {
 563         return secureRandomSpi;
 564     }
 565 
 566     /**
 567      * Returns the provider of this {@code SecureRandom} object.
 568      *
 569      * @return the provider of this {@code SecureRandom} object.




 286      * {@code SecureRandomSpi} implementation from the first
 287      * Provider that supports the specified algorithm is returned.
 288      *
 289      * <p> Note that the list of registered providers may be retrieved via
 290      * the {@link Security#getProviders() Security.getProviders()} method.
 291      *
 292      * @implNote
 293      * The JDK Reference Implementation additionally uses the
 294      * {@code jdk.security.provider.preferred}
 295      * {@link Security#getProperty(String) Security} property to determine
 296      * the preferred provider order for the specified algorithm. This
 297      * may be different than the order of providers returned by
 298      * {@link Security#getProviders() Security.getProviders()}.
 299      *
 300      * @param algorithm the name of the RNG algorithm.
 301      * See the {@code SecureRandom} section in the <a href=
 302      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 303      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 304      * for information about standard RNG algorithm names.
 305      *
 306      * @return the new {@code SecureRandom} object
 307      *
 308      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 309      *         {@code SecureRandomSpi} implementation for the
 310      *         specified algorithm
 311      *
 312      * @throws NullPointerException if {@code algorithm} is {@code null}
 313      *
 314      * @see Provider
 315      *
 316      * @since 1.2
 317      */
 318     public static SecureRandom getInstance(String algorithm)
 319             throws NoSuchAlgorithmException {
 320         Objects.requireNonNull(algorithm, "null algorithm name");
 321         Instance instance = GetInstance.getInstance("SecureRandom",
 322                 SecureRandomSpi.class, algorithm);
 323         return new SecureRandom((SecureRandomSpi)instance.impl,
 324                 instance.provider, algorithm);
 325     }
 326 
 327     /**
 328      * Returns a {@code SecureRandom} object that implements the specified
 329      * Random Number Generator (RNG) algorithm.
 330      *
 331      * <p> A new {@code SecureRandom} object encapsulating the
 332      * {@code SecureRandomSpi} implementation from the specified provider
 333      * is returned.  The specified provider must be registered
 334      * in the security provider list.
 335      *
 336      * <p> Note that the list of registered providers may be retrieved via
 337      * the {@link Security#getProviders() Security.getProviders()} method.
 338      *
 339      * @param algorithm the name of the RNG algorithm.
 340      * See the {@code SecureRandom} section in the <a href=
 341      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 342      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 343      * for information about standard RNG algorithm names.
 344      *
 345      * @param provider the name of the provider.
 346      *
 347      * @return the new {@code SecureRandom} object
 348      *
 349      * @throws IllegalArgumentException if the provider name is {@code null}
 350      *         or empty
 351      *
 352      * @throws NoSuchAlgorithmException if a {@code SecureRandomSpi}
 353      *         implementation for the specified algorithm is not
 354      *         available from the specified provider
 355      *
 356      * @throws NoSuchProviderException if the specified provider is not
 357      *         registered in the security provider list
 358      *
 359      * @throws NullPointerException if {@code algorithm} is {@code null}

 360      *
 361      * @see Provider
 362      *
 363      * @since 1.2
 364      */
 365     public static SecureRandom getInstance(String algorithm, String provider)
 366             throws NoSuchAlgorithmException, NoSuchProviderException {
 367         Objects.requireNonNull(algorithm, "null algorithm name");
 368         Instance instance = GetInstance.getInstance("SecureRandom",
 369             SecureRandomSpi.class, algorithm, provider);
 370         return new SecureRandom((SecureRandomSpi)instance.impl,
 371             instance.provider, algorithm);
 372     }
 373 
 374     /**
 375      * Returns a {@code SecureRandom} object that implements the specified
 376      * Random Number Generator (RNG) algorithm.
 377      *
 378      * <p> A new {@code SecureRandom} object encapsulating the
 379      * {@code SecureRandomSpi} implementation from the specified {@code Provider}
 380      * object is returned.  Note that the specified {@code Provider} object
 381      * does not have to be registered in the provider list.
 382      *
 383      * @param algorithm the name of the RNG algorithm.
 384      * See the {@code SecureRandom} section in the <a href=
 385      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 386      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 387      * for information about standard RNG algorithm names.
 388      *
 389      * @param provider the provider.
 390      *
 391      * @return the new {@code SecureRandom} object
 392      *
 393      * @throws IllegalArgumentException if the specified provider is
 394      *         {@code null}
 395      *
 396      * @throws NoSuchAlgorithmException if a {@code SecureRandomSpi}
 397      *         implementation for the specified algorithm is not available
 398      *         from the specified {@code Provider} object
 399      *
 400      * @throws NullPointerException if {@code algorithm} is {@code null}
 401      *
 402      * @see Provider
 403      *
 404      * @since 1.4
 405      */
 406     public static SecureRandom getInstance(String algorithm,
 407             Provider provider) throws NoSuchAlgorithmException {
 408         Objects.requireNonNull(algorithm, "null algorithm name");
 409         Instance instance = GetInstance.getInstance("SecureRandom",
 410             SecureRandomSpi.class, algorithm, provider);
 411         return new SecureRandom((SecureRandomSpi)instance.impl,
 412             instance.provider, algorithm);
 413     }
 414 
 415     /**
 416      * Returns a {@code SecureRandom} object that implements the specified
 417      * Random Number Generator (RNG) algorithm and supports the specified
 418      * {@code SecureRandomParameters} request.
 419      *
 420      * <p> This method traverses the list of registered security Providers,
 421      * starting with the most preferred Provider.
 422      * A new {@code SecureRandom} object encapsulating the
 423      * {@code SecureRandomSpi} implementation from the first
 424      * Provider that supports the specified algorithm and the specified
 425      * {@code SecureRandomParameters} is returned.
 426      *
 427      * <p> Note that the list of registered providers may be retrieved via
 428      * the {@link Security#getProviders() Security.getProviders()} method.
 429      *
 430      * @implNote
 431      * The JDK Reference Implementation additionally uses the
 432      * {@code jdk.security.provider.preferred} property to determine
 433      * the preferred provider order for the specified algorithm. This
 434      * may be different than the order of providers returned by
 435      * {@link Security#getProviders() Security.getProviders()}.
 436      *
 437      * @param algorithm the name of the RNG algorithm.
 438      * See the {@code SecureRandom} section in the <a href=
 439      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 440      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 441      * for information about standard RNG algorithm names.
 442      *
 443      * @param params the {@code SecureRandomParameters}
 444      *               the newly created {@code SecureRandom} object must support.
 445      *
 446      * @return the new {@code SecureRandom} object
 447      *
 448      * @throws IllegalArgumentException if the specified params is
 449      *         {@code null}
 450      *
 451      * @throws NoSuchAlgorithmException if no Provider supports a
 452      *         {@code SecureRandomSpi} implementation for the specified
 453      *         algorithm and parameters
 454      *
 455      * @throws NullPointerException if {@code algorithm} is {@code null}
 456      *
 457      * @see Provider
 458      *
 459      * @since 9
 460      */
 461     public static SecureRandom getInstance(
 462             String algorithm, SecureRandomParameters params)
 463             throws NoSuchAlgorithmException {
 464         Objects.requireNonNull(algorithm, "null algorithm name");
 465         if (params == null) {
 466             throw new IllegalArgumentException("params cannot be null");
 467         }
 468         Instance instance = GetInstance.getInstance("SecureRandom",
 469                 SecureRandomSpi.class, algorithm, params);
 470         return new SecureRandom((SecureRandomSpi)instance.impl,
 471                 instance.provider, algorithm);
 472     }
 473 
 474     /**
 475      * Returns a {@code SecureRandom} object that implements the specified
 476      * Random Number Generator (RNG) algorithm and supports the specified
 477      * {@code SecureRandomParameters} request.
 478      *
 479      * <p> A new {@code SecureRandom} object encapsulating the
 480      * {@code SecureRandomSpi} implementation from the specified provider
 481      * is returned.  The specified provider must be registered
 482      * in the security provider list.
 483      *
 484      * <p> Note that the list of registered providers may be retrieved via
 485      * the {@link Security#getProviders() Security.getProviders()} method.
 486      *
 487      * @param algorithm the name of the RNG algorithm.
 488      * See the {@code SecureRandom} section in the <a href=
 489      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 490      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 491      * for information about standard RNG algorithm names.
 492      *
 493      * @param params the {@code SecureRandomParameters}
 494      *               the newly created {@code SecureRandom} object must support.
 495      *
 496      * @param provider the name of the provider.
 497      *
 498      * @return the new {@code SecureRandom} object
 499      *
 500      * @throws IllegalArgumentException if the provider name is {@code null}
 501      *         or empty, or params is {@code null}
 502      *
 503      * @throws NoSuchAlgorithmException if the specified provider does not
 504      *         support a {@code SecureRandomSpi} implementation for the
 505      *         specified algorithm and parameters
 506      *
 507      * @throws NoSuchProviderException if the specified provider is not
 508      *         registered in the security provider list
 509      *
 510      * @throws NullPointerException if {@code algorithm} is {@code null}

 511      *
 512      * @see Provider
 513      *
 514      * @since 9
 515      */
 516     public static SecureRandom getInstance(String algorithm,
 517             SecureRandomParameters params, String provider)
 518             throws NoSuchAlgorithmException, NoSuchProviderException {
 519         Objects.requireNonNull(algorithm, "null algorithm name");
 520         if (params == null) {
 521             throw new IllegalArgumentException("params cannot be null");
 522         }
 523         Instance instance = GetInstance.getInstance("SecureRandom",
 524                 SecureRandomSpi.class, algorithm, params, provider);
 525         return new SecureRandom((SecureRandomSpi)instance.impl,
 526                 instance.provider, algorithm);
 527     }
 528 
 529     /**
 530      * Returns a {@code SecureRandom} object that implements the specified
 531      * Random Number Generator (RNG) algorithm and supports the specified
 532      * {@code SecureRandomParameters} request.
 533      *
 534      * <p> A new {@code SecureRandom} object encapsulating the
 535      * {@code SecureRandomSpi} implementation from the specified
 536      * {@code Provider} object is returned.  Note that the specified
 537      * {@code Provider} object does not have to be registered in the
 538      * provider list.
 539      *
 540      * @param algorithm the name of the RNG algorithm.
 541      * See the {@code SecureRandom} section in the <a href=
 542      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SecureRandom">
 543      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 544      * for information about standard RNG algorithm names.
 545      *
 546      * @param params the {@code SecureRandomParameters}
 547      *               the newly created {@code SecureRandom} object must support.
 548      *
 549      * @param provider the provider.
 550      *
 551      * @return the new {@code SecureRandom} object
 552      *
 553      * @throws IllegalArgumentException if the specified provider or params
 554      *         is {@code null}
 555      *
 556      * @throws NoSuchAlgorithmException if the specified provider does not
 557      *         support a {@code SecureRandomSpi} implementation for the
 558      *         specified algorithm and parameters
 559      *
 560      * @throws NullPointerException if {@code algorithm} is {@code null}

 561      *
 562      * @see Provider
 563      *
 564      * @since 9
 565      */
 566     public static SecureRandom getInstance(String algorithm,
 567             SecureRandomParameters params, Provider provider)
 568             throws NoSuchAlgorithmException {
 569         Objects.requireNonNull(algorithm, "null algorithm name");
 570         if (params == null) {
 571             throw new IllegalArgumentException("params cannot be null");
 572         }
 573         Instance instance = GetInstance.getInstance("SecureRandom",
 574                 SecureRandomSpi.class, algorithm, params, provider);
 575         return new SecureRandom((SecureRandomSpi)instance.impl,
 576                 instance.provider, algorithm);
 577     }
 578 
 579     /**
 580      * Returns the {@code SecureRandomSpi} of this {@code SecureRandom} object.
 581      */
 582     SecureRandomSpi getSecureRandomSpi() {
 583         return secureRandomSpi;
 584     }
 585 
 586     /**
 587      * Returns the provider of this {@code SecureRandom} object.
 588      *
 589      * @return the provider of this {@code SecureRandom} object.


< prev index next >