< prev index next >

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

Print this page
rev 15967 : [mq]: GetInstance


 199      * KeyGeneratorSpi implementation from the first
 200      * Provider that supports the specified algorithm is returned.
 201      *
 202      * <p> Note that the list of registered providers may be retrieved via
 203      * the {@link Security#getProviders() Security.getProviders()} method.
 204      *
 205      * @implNote
 206      * The JDK Reference Implementation additionally uses the
 207      * {@code jdk.security.provider.preferred}
 208      * {@link Security#getProperty(String) Security} property to determine
 209      * the preferred provider order for the specified algorithm. This
 210      * may be different than the order of providers returned by
 211      * {@link Security#getProviders() Security.getProviders()}.
 212      *
 213      * @param algorithm the standard name of the requested key algorithm.
 214      * See the KeyGenerator section in the <a href=
 215      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyGenerator">
 216      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 217      * for information about standard algorithm names.
 218      *
 219      * @return the new {@code KeyGenerator} object.
 220      *
 221      * @exception NullPointerException if the specified algorithm is null.


 222      *
 223      * @exception NoSuchAlgorithmException if no Provider supports a
 224      *          KeyGeneratorSpi implementation for the
 225      *          specified algorithm.
 226      *
 227      * @see java.security.Provider
 228      */
 229     public static final KeyGenerator getInstance(String algorithm)
 230             throws NoSuchAlgorithmException {

 231         return new KeyGenerator(algorithm);
 232     }
 233 
 234     /**
 235      * Returns a {@code KeyGenerator} object that generates secret keys
 236      * for the specified algorithm.
 237      *
 238      * <p> A new KeyGenerator object encapsulating the
 239      * KeyGeneratorSpi implementation from the specified provider
 240      * is returned.  The specified provider must be registered
 241      * in the security provider list.
 242      *
 243      * <p> Note that the list of registered providers may be retrieved via
 244      * the {@link Security#getProviders() Security.getProviders()} method.
 245      *
 246      * @param algorithm the standard name of the requested key algorithm.
 247      * See the KeyGenerator section in the <a href=
 248      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyGenerator">
 249      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 250      * for information about standard algorithm names.
 251      *
 252      * @param provider the name of the provider.
 253      *
 254      * @return the new {@code KeyGenerator} object.
 255      *
 256      * @exception NullPointerException if the specified algorithm is null.

 257      *
 258      * @exception NoSuchAlgorithmException if a KeyGeneratorSpi
 259      *          implementation for the specified algorithm is not
 260      *          available from the specified provider.
 261      *
 262      * @exception NoSuchProviderException if the specified provider is not
 263      *          registered in the security provider list.
 264      *
 265      * @exception IllegalArgumentException if the {@code provider}
 266      *          is null or empty.
 267      *
 268      * @see java.security.Provider
 269      */
 270     public static final KeyGenerator getInstance(String algorithm,
 271             String provider) throws NoSuchAlgorithmException,
 272             NoSuchProviderException {

 273         Instance instance = JceSecurity.getInstance("KeyGenerator",
 274                 KeyGeneratorSpi.class, algorithm, provider);
 275         return new KeyGenerator((KeyGeneratorSpi)instance.impl,
 276                 instance.provider, algorithm);
 277     }
 278 
 279     /**
 280      * Returns a {@code KeyGenerator} object that generates secret keys
 281      * for the specified algorithm.
 282      *
 283      * <p> A new KeyGenerator object encapsulating the
 284      * KeyGeneratorSpi implementation from the specified Provider
 285      * object is returned.  Note that the specified Provider object
 286      * does not have to be registered in the provider list.
 287      *
 288      * @param algorithm the standard name of the requested key algorithm.
 289      * See the KeyGenerator section in the <a href=
 290      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyGenerator">
 291      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 292      * for information about standard algorithm names.
 293      *
 294      * @param provider the provider.
 295      *
 296      * @return the new {@code KeyGenerator} object.
 297      *
 298      * @exception NullPointerException if the specified algorithm is null.

 299      *
 300      * @exception NoSuchAlgorithmException if a KeyGeneratorSpi
 301      *          implementation for the specified algorithm is not available
 302      *          from the specified Provider object.
 303      *
 304      * @exception IllegalArgumentException if the {@code provider}
 305      *          is null.
 306      *
 307      * @see java.security.Provider
 308      */
 309     public static final KeyGenerator getInstance(String algorithm,
 310             Provider provider) throws NoSuchAlgorithmException {

 311         Instance instance = JceSecurity.getInstance("KeyGenerator",
 312                 KeyGeneratorSpi.class, algorithm, provider);
 313         return new KeyGenerator((KeyGeneratorSpi)instance.impl,
 314                 instance.provider, algorithm);
 315     }
 316 
 317     /**
 318      * Returns the provider of this {@code KeyGenerator} object.
 319      *
 320      * @return the provider of this {@code KeyGenerator} object
 321      */
 322     public final Provider getProvider() {
 323         synchronized (lock) {
 324             disableFailover();
 325             return provider;
 326         }
 327     }
 328 
 329     /**
 330      * Update the active spi of this class and return the next




 199      * KeyGeneratorSpi implementation from the first
 200      * Provider that supports the specified algorithm is returned.
 201      *
 202      * <p> Note that the list of registered providers may be retrieved via
 203      * the {@link Security#getProviders() Security.getProviders()} method.
 204      *
 205      * @implNote
 206      * The JDK Reference Implementation additionally uses the
 207      * {@code jdk.security.provider.preferred}
 208      * {@link Security#getProperty(String) Security} property to determine
 209      * the preferred provider order for the specified algorithm. This
 210      * may be different than the order of providers returned by
 211      * {@link Security#getProviders() Security.getProviders()}.
 212      *
 213      * @param algorithm the standard name of the requested key algorithm.
 214      * See the KeyGenerator section in the <a href=
 215      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyGenerator">
 216      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 217      * for information about standard algorithm names.
 218      *
 219      * @return the new {@code KeyGenerator} object
 220      *
 221      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 222      *         {@code KeyGeneratorSpi} implementation for the
 223      *         specified algorithm
 224      *
 225      * @throws NullPointerException if {@code algorithm} is {@code null}


 226      *
 227      * @see java.security.Provider
 228      */
 229     public static final KeyGenerator getInstance(String algorithm)
 230             throws NoSuchAlgorithmException {
 231         Objects.requireNonNull(algorithm, "null algorithm name");
 232         return new KeyGenerator(algorithm);
 233     }
 234 
 235     /**
 236      * Returns a {@code KeyGenerator} object that generates secret keys
 237      * for the specified algorithm.
 238      *
 239      * <p> A new KeyGenerator object encapsulating the
 240      * KeyGeneratorSpi implementation from the specified provider
 241      * is returned.  The specified provider must be registered
 242      * in the security provider list.
 243      *
 244      * <p> Note that the list of registered providers may be retrieved via
 245      * the {@link Security#getProviders() Security.getProviders()} method.
 246      *
 247      * @param algorithm the standard name of the requested key algorithm.
 248      * See the KeyGenerator section in the <a href=
 249      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyGenerator">
 250      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 251      * for information about standard algorithm names.
 252      *
 253      * @param provider the name of the provider.
 254      *
 255      * @return the new {@code KeyGenerator} object
 256      *
 257      * @throws IllegalArgumentException if the {@code provider}
 258      *         is {@code null} or empty
 259      *
 260      * @throws NoSuchAlgorithmException if a {@code KeyGeneratorSpi}
 261      *         implementation for the specified algorithm is not
 262      *         available from the specified provider
 263      *
 264      * @throws NoSuchProviderException if the specified provider is not
 265      *         registered in the security provider list
 266      *
 267      * @throws NullPointerException if {@code algorithm} is {@code null}

 268      *
 269      * @see java.security.Provider
 270      */
 271     public static final KeyGenerator getInstance(String algorithm,
 272             String provider) throws NoSuchAlgorithmException,
 273             NoSuchProviderException {
 274         Objects.requireNonNull(algorithm, "null algorithm name");
 275         Instance instance = JceSecurity.getInstance("KeyGenerator",
 276                 KeyGeneratorSpi.class, algorithm, provider);
 277         return new KeyGenerator((KeyGeneratorSpi)instance.impl,
 278                 instance.provider, algorithm);
 279     }
 280 
 281     /**
 282      * Returns a {@code KeyGenerator} object that generates secret keys
 283      * for the specified algorithm.
 284      *
 285      * <p> A new KeyGenerator object encapsulating the
 286      * KeyGeneratorSpi implementation from the specified Provider
 287      * object is returned.  Note that the specified Provider object
 288      * does not have to be registered in the provider list.
 289      *
 290      * @param algorithm the standard name of the requested key algorithm.
 291      * See the KeyGenerator section in the <a href=
 292      * "{@docRoot}/../technotes/guides/security/StandardNames.html#KeyGenerator">
 293      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 294      * for information about standard algorithm names.
 295      *
 296      * @param provider the provider.
 297      *
 298      * @return the new {@code KeyGenerator} object
 299      *
 300      * @throws IllegalArgumentException if the {@code provider}
 301      *         is {@code null}
 302      *
 303      * @throws NoSuchAlgorithmException if a {@code KeyGeneratorSpi}
 304      *         implementation for the specified algorithm is not available
 305      *         from the specified {@code Provider} object
 306      *
 307      * @throws NullPointerException if {@code algorithm} is {@code null}

 308      *
 309      * @see java.security.Provider
 310      */
 311     public static final KeyGenerator getInstance(String algorithm,
 312             Provider provider) throws NoSuchAlgorithmException {
 313         Objects.requireNonNull(algorithm, "null algorithm name");
 314         Instance instance = JceSecurity.getInstance("KeyGenerator",
 315                 KeyGeneratorSpi.class, algorithm, provider);
 316         return new KeyGenerator((KeyGeneratorSpi)instance.impl,
 317                 instance.provider, algorithm);
 318     }
 319 
 320     /**
 321      * Returns the provider of this {@code KeyGenerator} object.
 322      *
 323      * @return the provider of this {@code KeyGenerator} object
 324      */
 325     public final Provider getProvider() {
 326         synchronized (lock) {
 327             disableFailover();
 328             return provider;
 329         }
 330     }
 331 
 332     /**
 333      * Update the active spi of this class and return the next


< prev index next >