< prev index next >

src/java.base/share/classes/javax/crypto/Cipher.java

Print this page
rev 15967 : [mq]: GetInstance


 476      * Provider that supports the specified algorithm is returned.
 477      *
 478      * <p> Note that the list of registered providers may be retrieved via
 479      * the {@link Security#getProviders() Security.getProviders()} method.
 480      *
 481      * @implNote
 482      * The JDK Reference Implementation additionally uses the
 483      * {@code jdk.security.provider.preferred}
 484      * {@link Security#getProperty(String) Security} property to determine
 485      * the preferred provider order for the specified algorithm. This
 486      * may be different than the order of providers returned by
 487      * {@link Security#getProviders() Security.getProviders()}.
 488      *
 489      * @param transformation the name of the transformation, e.g.,
 490      * <i>DES/CBC/PKCS5Padding</i>.
 491      * See the Cipher section in the <a href=
 492      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 493      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 494      * for information about standard transformation names.
 495      *
 496      * @return a cipher that implements the requested transformation.
 497      *
 498      * @exception NoSuchAlgorithmException if {@code transformation}
 499      *          is null, empty, in an invalid format,
 500      *          or if no Provider supports a CipherSpi implementation for the
 501      *          specified algorithm.
 502      *
 503      * @exception NoSuchPaddingException if {@code transformation}
 504      *          contains a padding scheme that is not available.
 505      *
 506      * @see java.security.Provider
 507      */
 508     public static final Cipher getInstance(String transformation)
 509             throws NoSuchAlgorithmException, NoSuchPaddingException
 510     {
 511         List<Transform> transforms = getTransforms(transformation);
 512         List<ServiceId> cipherServices = new ArrayList<>(transforms.size());
 513         for (Transform transform : transforms) {
 514             cipherServices.add(new ServiceId("Cipher", transform.transform));
 515         }
 516         List<Service> services = GetInstance.getServices(cipherServices);
 517         // make sure there is at least one service from a signed provider
 518         // and that it can use the specified mode and padding
 519         Iterator<Service> t = services.iterator();
 520         Exception failure = null;
 521         while (t.hasNext()) {
 522             Service s = t.next();
 523             if (JceSecurity.canUseProvider(s.getProvider()) == false) {
 524                 continue;


 553      * Returns a {@code Cipher} object that implements the specified
 554      * transformation.
 555      *
 556      * <p> A new Cipher object encapsulating the
 557      * CipherSpi implementation from the specified provider
 558      * is returned.  The specified provider must be registered
 559      * in the security provider list.
 560      *
 561      * <p> Note that the list of registered providers may be retrieved via
 562      * the {@link Security#getProviders() Security.getProviders()} method.
 563      *
 564      * @param transformation the name of the transformation,
 565      * e.g., <i>DES/CBC/PKCS5Padding</i>.
 566      * See the Cipher section in the <a href=
 567      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 568      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 569      * for information about standard transformation names.
 570      *
 571      * @param provider the name of the provider.
 572      *
 573      * @return a cipher that implements the requested transformation.
 574      *
 575      * @exception NoSuchAlgorithmException if {@code transformation}
 576      *          is null, empty, in an invalid format,
 577      *          or if a CipherSpi implementation for the specified algorithm
 578      *          is not available from the specified provider.
 579      *
 580      * @exception NoSuchProviderException if the specified provider is not
 581      *          registered in the security provider list.



 582      *
 583      * @exception NoSuchPaddingException if {@code transformation}
 584      *          contains a padding scheme that is not available.
 585      *
 586      * @exception IllegalArgumentException if the {@code provider}
 587      *          is null or empty.
 588      *
 589      * @see java.security.Provider
 590      */
 591     public static final Cipher getInstance(String transformation,
 592                                            String provider)
 593             throws NoSuchAlgorithmException, NoSuchProviderException,
 594             NoSuchPaddingException
 595     {
 596         if ((provider == null) || (provider.length() == 0)) {
 597             throw new IllegalArgumentException("Missing provider");
 598         }
 599         Provider p = Security.getProvider(provider);
 600         if (p == null) {
 601             throw new NoSuchProviderException("No such provider: " +
 602                                               provider);
 603         }
 604         return getInstance(transformation, p);
 605     }
 606 
 607     /**
 608      * Returns a {@code Cipher} object that implements the specified
 609      * transformation.
 610      *
 611      * <p> A new Cipher object encapsulating the
 612      * CipherSpi implementation from the specified Provider
 613      * object is returned.  Note that the specified Provider object
 614      * does not have to be registered in the provider list.
 615      *
 616      * @param transformation the name of the transformation,
 617      * e.g., <i>DES/CBC/PKCS5Padding</i>.
 618      * See the Cipher section in the <a href=
 619      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 620      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 621      * for information about standard transformation names.
 622      *
 623      * @param provider the provider.
 624      *
 625      * @return a cipher that implements the requested transformation.
 626      *
 627      * @exception NoSuchAlgorithmException if {@code transformation}
 628      *          is null, empty, in an invalid format,
 629      *          or if a CipherSpi implementation for the specified algorithm
 630      *          is not available from the specified Provider object.
 631      *
 632      * @exception NoSuchPaddingException if {@code transformation}
 633      *          contains a padding scheme that is not available.



 634      *
 635      * @exception IllegalArgumentException if the {@code provider}
 636      *          is null.
 637      *
 638      * @see java.security.Provider
 639      */
 640     public static final Cipher getInstance(String transformation,
 641                                            Provider provider)
 642             throws NoSuchAlgorithmException, NoSuchPaddingException
 643     {
 644         if (provider == null) {
 645             throw new IllegalArgumentException("Missing provider");
 646         }
 647         Exception failure = null;
 648         List<Transform> transforms = getTransforms(transformation);
 649         boolean providerChecked = false;
 650         String paddingError = null;
 651         for (Transform tr : transforms) {
 652             Service s = provider.getService("Cipher", tr.transform);
 653             if (s == null) {
 654                 continue;
 655             }
 656             if (providerChecked == false) {




 476      * Provider that supports the specified algorithm is returned.
 477      *
 478      * <p> Note that the list of registered providers may be retrieved via
 479      * the {@link Security#getProviders() Security.getProviders()} method.
 480      *
 481      * @implNote
 482      * The JDK Reference Implementation additionally uses the
 483      * {@code jdk.security.provider.preferred}
 484      * {@link Security#getProperty(String) Security} property to determine
 485      * the preferred provider order for the specified algorithm. This
 486      * may be different than the order of providers returned by
 487      * {@link Security#getProviders() Security.getProviders()}.
 488      *
 489      * @param transformation the name of the transformation, e.g.,
 490      * <i>DES/CBC/PKCS5Padding</i>.
 491      * See the Cipher section in the <a href=
 492      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 493      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 494      * for information about standard transformation names.
 495      *
 496      * @return a cipher that implements the requested transformation
 497      *
 498      * @throws NoSuchAlgorithmException if {@code transformation}
 499      *         is {@code null}, empty, in an invalid format,
 500      *         or if no {@code Provider} supports a {@code CipherSpi}
 501      *         implementation for the specified algorithm
 502      *
 503      * @throws NoSuchPaddingException if {@code transformation}
 504      *         contains a padding scheme that is not available
 505      *
 506      * @see java.security.Provider
 507      */
 508     public static final Cipher getInstance(String transformation)
 509             throws NoSuchAlgorithmException, NoSuchPaddingException
 510     {
 511         List<Transform> transforms = getTransforms(transformation);
 512         List<ServiceId> cipherServices = new ArrayList<>(transforms.size());
 513         for (Transform transform : transforms) {
 514             cipherServices.add(new ServiceId("Cipher", transform.transform));
 515         }
 516         List<Service> services = GetInstance.getServices(cipherServices);
 517         // make sure there is at least one service from a signed provider
 518         // and that it can use the specified mode and padding
 519         Iterator<Service> t = services.iterator();
 520         Exception failure = null;
 521         while (t.hasNext()) {
 522             Service s = t.next();
 523             if (JceSecurity.canUseProvider(s.getProvider()) == false) {
 524                 continue;


 553      * Returns a {@code Cipher} object that implements the specified
 554      * transformation.
 555      *
 556      * <p> A new Cipher object encapsulating the
 557      * CipherSpi implementation from the specified provider
 558      * is returned.  The specified provider must be registered
 559      * in the security provider list.
 560      *
 561      * <p> Note that the list of registered providers may be retrieved via
 562      * the {@link Security#getProviders() Security.getProviders()} method.
 563      *
 564      * @param transformation the name of the transformation,
 565      * e.g., <i>DES/CBC/PKCS5Padding</i>.
 566      * See the Cipher section in the <a href=
 567      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 568      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 569      * for information about standard transformation names.
 570      *
 571      * @param provider the name of the provider.
 572      *
 573      * @return a cipher that implements the requested transformation
 574      *
 575      * @throws IllegalArgumentException if the {@code provider}
 576      *         is {@code null} or empty


 577      *
 578      * @throws NoSuchAlgorithmException if {@code transformation}
 579      *         is {@code null}, empty, in an invalid format,
 580      *         or if a {@code CipherSpi} implementation for the
 581      *         specified algorithm is not available from the specified
 582      *         provider
 583      *
 584      * @throws NoSuchPaddingException if {@code transformation}
 585      *         contains a padding scheme that is not available
 586      *
 587      * @throws NoSuchProviderException if the specified provider is not
 588      *         registered in the security provider list
 589      *
 590      * @see java.security.Provider
 591      */
 592     public static final Cipher getInstance(String transformation,
 593                                            String provider)
 594             throws NoSuchAlgorithmException, NoSuchProviderException,
 595             NoSuchPaddingException
 596     {
 597         if ((provider == null) || (provider.length() == 0)) {
 598             throw new IllegalArgumentException("Missing provider");
 599         }
 600         Provider p = Security.getProvider(provider);
 601         if (p == null) {
 602             throw new NoSuchProviderException("No such provider: " +
 603                                               provider);
 604         }
 605         return getInstance(transformation, p);
 606     }
 607 
 608     /**
 609      * Returns a {@code Cipher} object that implements the specified
 610      * transformation.
 611      *
 612      * <p> A new Cipher object encapsulating the
 613      * CipherSpi implementation from the specified Provider
 614      * object is returned.  Note that the specified Provider object
 615      * does not have to be registered in the provider list.
 616      *
 617      * @param transformation the name of the transformation,
 618      * e.g., <i>DES/CBC/PKCS5Padding</i>.
 619      * See the Cipher section in the <a href=
 620      *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 621      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 622      * for information about standard transformation names.
 623      *
 624      * @param provider the provider.
 625      *
 626      * @return a cipher that implements the requested transformation
 627      *
 628      * @throws IllegalArgumentException if the {@code provider}
 629      *         is {@code null}


 630      *
 631      * @throws NoSuchAlgorithmException if {@code transformation}
 632      *         is {@code null}, empty, in an invalid format,
 633      *         or if a {@code CipherSpi} implementation for the
 634      *         specified algorithm is not available from the specified
 635      *         {@code Provider} object
 636      *
 637      * @throws NoSuchPaddingException if {@code transformation}
 638      *         contains a padding scheme that is not available
 639      *
 640      * @see java.security.Provider
 641      */
 642     public static final Cipher getInstance(String transformation,
 643                                            Provider provider)
 644             throws NoSuchAlgorithmException, NoSuchPaddingException
 645     {
 646         if (provider == null) {
 647             throw new IllegalArgumentException("Missing provider");
 648         }
 649         Exception failure = null;
 650         List<Transform> transforms = getTransforms(transformation);
 651         boolean providerChecked = false;
 652         String paddingError = null;
 653         for (Transform tr : transforms) {
 654             Service s = provider.getService("Cipher", tr.transform);
 655             if (s == null) {
 656                 continue;
 657             }
 658             if (providerChecked == false) {


< prev index next >