< prev index next >

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

Print this page
rev 15967 : [mq]: GetInstance


 148      * Provider that supports the specified algorithm is returned.
 149      *
 150      * <p> Note that the list of registered providers may be retrieved via
 151      * the {@link Security#getProviders() Security.getProviders()} method.
 152      *
 153      * @implNote
 154      * The JDK Reference Implementation additionally uses the
 155      * {@code jdk.security.provider.preferred}
 156      * {@link Security#getProperty(String) Security} property to determine
 157      * the preferred provider order for the specified algorithm. This
 158      * may be different than the order of providers returned by
 159      * {@link Security#getProviders() Security.getProviders()}.
 160      *
 161      * @param algorithm the standard name of the requested key agreement
 162      * algorithm.
 163      * See the KeyAgreement section in the <a href=
 164      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
 165      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 166      * for information about standard algorithm names.
 167      *
 168      * @return the new {@code KeyAgreement} object.
 169      *
 170      * @exception NullPointerException if the specified algorithm
 171      *          is null.

 172      *
 173      * @exception NoSuchAlgorithmException if no Provider supports a
 174      *          KeyAgreementSpi implementation for the
 175      *          specified algorithm.
 176      *
 177      * @see java.security.Provider
 178      */
 179     public static final KeyAgreement getInstance(String algorithm)
 180             throws NoSuchAlgorithmException {

 181         List<Service> services =
 182                 GetInstance.getServices("KeyAgreement", algorithm);
 183         // make sure there is at least one service from a signed provider
 184         Iterator<Service> t = services.iterator();
 185         while (t.hasNext()) {
 186             Service s = t.next();
 187             if (JceSecurity.canUseProvider(s.getProvider()) == false) {
 188                 continue;
 189             }
 190             return new KeyAgreement(s, t, algorithm);
 191         }
 192         throw new NoSuchAlgorithmException
 193                                 ("Algorithm " + algorithm + " not available");
 194     }
 195 
 196     /**
 197      * Returns a {@code KeyAgreement} object that implements the
 198      * specified key agreement algorithm.
 199      *
 200      * <p> A new KeyAgreement object encapsulating the
 201      * KeyAgreementSpi implementation from the specified provider
 202      * is returned.  The specified provider must be registered
 203      * in the security provider list.
 204      *
 205      * <p> Note that the list of registered providers may be retrieved via
 206      * the {@link Security#getProviders() Security.getProviders()} method.
 207      *
 208      * @param algorithm the standard name of the requested key agreement
 209      * algorithm.
 210      * See the KeyAgreement section in the <a href=
 211      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
 212      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 213      * for information about standard algorithm names.
 214      *
 215      * @param provider the name of the provider.
 216      *
 217      * @return the new {@code KeyAgreement} object.
 218      *
 219      * @exception NullPointerException if the specified algorithm
 220      *          is null.
 221      *
 222      * @exception NoSuchAlgorithmException if a KeyAgreementSpi
 223      *          implementation for the specified algorithm is not
 224      *          available from the specified provider.
 225      *
 226      * @exception NoSuchProviderException if the specified provider is not
 227      *          registered in the security provider list.
 228      *
 229      * @exception IllegalArgumentException if the {@code provider}
 230      *          is null or empty.
 231      *
 232      * @see java.security.Provider
 233      */
 234     public static final KeyAgreement getInstance(String algorithm,
 235             String provider) throws NoSuchAlgorithmException,
 236             NoSuchProviderException {

 237         Instance instance = JceSecurity.getInstance
 238                 ("KeyAgreement", KeyAgreementSpi.class, algorithm, provider);
 239         return new KeyAgreement((KeyAgreementSpi)instance.impl,
 240                 instance.provider, algorithm);
 241     }
 242 
 243     /**
 244      * Returns a {@code KeyAgreement} object that implements the
 245      * specified key agreement algorithm.
 246      *
 247      * <p> A new KeyAgreement object encapsulating the
 248      * KeyAgreementSpi implementation from the specified Provider
 249      * object is returned.  Note that the specified Provider object
 250      * does not have to be registered in the provider list.
 251      *
 252      * @param algorithm the standard name of the requested key agreement
 253      * algorithm.
 254      * See the KeyAgreement section in the <a href=
 255      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
 256      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 257      * for information about standard algorithm names.
 258      *
 259      * @param provider the provider.
 260      *
 261      * @return the new {@code KeyAgreement} object.
 262      *
 263      * @exception NullPointerException if the specified algorithm
 264      *          is null.
 265      *
 266      * @exception NoSuchAlgorithmException if a KeyAgreementSpi
 267      *          implementation for the specified algorithm is not available
 268      *          from the specified Provider object.
 269      *
 270      * @exception IllegalArgumentException if the {@code provider}
 271      *          is null.
 272      *
 273      * @see java.security.Provider
 274      */
 275     public static final KeyAgreement getInstance(String algorithm,
 276             Provider provider) throws NoSuchAlgorithmException {

 277         Instance instance = JceSecurity.getInstance
 278                 ("KeyAgreement", KeyAgreementSpi.class, algorithm, provider);
 279         return new KeyAgreement((KeyAgreementSpi)instance.impl,
 280                 instance.provider, algorithm);
 281     }
 282 
 283     // max number of debug warnings to print from chooseFirstProvider()
 284     private static int warnCount = 10;
 285 
 286     /**
 287      * Choose the Spi from the first provider available. Used if
 288      * delayed provider selection is not possible because init()
 289      * is not the first method called.
 290      */
 291     void chooseFirstProvider() {
 292         if (spi != null) {
 293             return;
 294         }
 295         synchronized (lock) {
 296             if (spi != null) {




 148      * Provider that supports the specified algorithm is returned.
 149      *
 150      * <p> Note that the list of registered providers may be retrieved via
 151      * the {@link Security#getProviders() Security.getProviders()} method.
 152      *
 153      * @implNote
 154      * The JDK Reference Implementation additionally uses the
 155      * {@code jdk.security.provider.preferred}
 156      * {@link Security#getProperty(String) Security} property to determine
 157      * the preferred provider order for the specified algorithm. This
 158      * may be different than the order of providers returned by
 159      * {@link Security#getProviders() Security.getProviders()}.
 160      *
 161      * @param algorithm the standard name of the requested key agreement
 162      * algorithm.
 163      * See the KeyAgreement section in the <a href=
 164      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
 165      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 166      * for information about standard algorithm names.
 167      *
 168      * @return the new {@code KeyAgreement} object
 169      *
 170      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 171      *         {@code KeyAgreementSpi} implementation for the
 172      *         specified algorithm
 173      *
 174      * @throws NullPointerException if {@code algorithm} is {@code null}


 175      *
 176      * @see java.security.Provider
 177      */
 178     public static final KeyAgreement getInstance(String algorithm)
 179             throws NoSuchAlgorithmException {
 180         Objects.requireNonNull(algorithm, "null algorithm name");
 181         List<Service> services =
 182                 GetInstance.getServices("KeyAgreement", algorithm);
 183         // make sure there is at least one service from a signed provider
 184         Iterator<Service> t = services.iterator();
 185         while (t.hasNext()) {
 186             Service s = t.next();
 187             if (JceSecurity.canUseProvider(s.getProvider()) == false) {
 188                 continue;
 189             }
 190             return new KeyAgreement(s, t, algorithm);
 191         }
 192         throw new NoSuchAlgorithmException
 193                                 ("Algorithm " + algorithm + " not available");
 194     }
 195 
 196     /**
 197      * Returns a {@code KeyAgreement} object that implements the
 198      * specified key agreement algorithm.
 199      *
 200      * <p> A new KeyAgreement object encapsulating the
 201      * KeyAgreementSpi implementation from the specified provider
 202      * is returned.  The specified provider must be registered
 203      * in the security provider list.
 204      *
 205      * <p> Note that the list of registered providers may be retrieved via
 206      * the {@link Security#getProviders() Security.getProviders()} method.
 207      *
 208      * @param algorithm the standard name of the requested key agreement
 209      * algorithm.
 210      * See the KeyAgreement section in the <a href=
 211      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
 212      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 213      * for information about standard algorithm names.
 214      *
 215      * @param provider the name of the provider.
 216      *
 217      * @return the new {@code KeyAgreement} object
 218      *
 219      * @throws IllegalArgumentException if the {@code provider}
 220      *         is {@code null} or empty
 221      *
 222      * @throws NoSuchAlgorithmException if a {@code KeyAgreementSpi}
 223      *         implementation for the specified algorithm is not
 224      *         available from the specified provider
 225      *
 226      * @throws NoSuchProviderException if the specified provider is not
 227      *         registered in the security provider list
 228      *
 229      * @throws NullPointerException if {@code algorithm} is {@code null}

 230      *
 231      * @see java.security.Provider
 232      */
 233     public static final KeyAgreement getInstance(String algorithm,
 234             String provider) throws NoSuchAlgorithmException,
 235             NoSuchProviderException {
 236         Objects.requireNonNull(algorithm, "null algorithm name");
 237         Instance instance = JceSecurity.getInstance
 238                 ("KeyAgreement", KeyAgreementSpi.class, algorithm, provider);
 239         return new KeyAgreement((KeyAgreementSpi)instance.impl,
 240                 instance.provider, algorithm);
 241     }
 242 
 243     /**
 244      * Returns a {@code KeyAgreement} object that implements the
 245      * specified key agreement algorithm.
 246      *
 247      * <p> A new KeyAgreement object encapsulating the
 248      * KeyAgreementSpi implementation from the specified Provider
 249      * object is returned.  Note that the specified Provider object
 250      * does not have to be registered in the provider list.
 251      *
 252      * @param algorithm the standard name of the requested key agreement
 253      * algorithm.
 254      * See the KeyAgreement section in the <a href=
 255      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyAgreement">
 256      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 257      * for information about standard algorithm names.
 258      *
 259      * @param provider the provider.
 260      *
 261      * @return the new {@code KeyAgreement} object
 262      *
 263      * @throws IllegalArgumentException if the {@code provider}
 264      *         is {@code null}
 265      *
 266      * @throws NoSuchAlgorithmException if a {@code KeyAgreementSpi}
 267      *         implementation for the specified algorithm is not available
 268      *         from the specified Provider object
 269      *
 270      * @throws NullPointerException if {@code algorithm} is {@code null}

 271      *
 272      * @see java.security.Provider
 273      */
 274     public static final KeyAgreement getInstance(String algorithm,
 275             Provider provider) throws NoSuchAlgorithmException {
 276         Objects.requireNonNull(algorithm, "null algorithm name");
 277         Instance instance = JceSecurity.getInstance
 278                 ("KeyAgreement", KeyAgreementSpi.class, algorithm, provider);
 279         return new KeyAgreement((KeyAgreementSpi)instance.impl,
 280                 instance.provider, algorithm);
 281     }
 282 
 283     // max number of debug warnings to print from chooseFirstProvider()
 284     private static int warnCount = 10;
 285 
 286     /**
 287      * Choose the Spi from the first provider available. Used if
 288      * delayed provider selection is not possible because init()
 289      * is not the first method called.
 290      */
 291     void chooseFirstProvider() {
 292         if (spi != null) {
 293             return;
 294         }
 295         synchronized (lock) {
 296             if (spi != null) {


< prev index next >