Path: blob/master/src/java.base/share/classes/java/security/KeyPairGeneratorSpi.java
41152 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627import java.security.spec.AlgorithmParameterSpec;2829/**30* <p> This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)31* for the {@code KeyPairGenerator} class, which is used to generate32* pairs of public and private keys.33*34* <p> All the abstract methods in this class must be implemented by each35* cryptographic service provider who wishes to supply the implementation36* of a key pair generator for a particular algorithm.37*38* <p> In case the client does not explicitly initialize the KeyPairGenerator39* (via a call to an {@code initialize} method), each provider must40* supply (and document) a default initialization.41* See the Keysize Restriction sections of the42* {@extLink security_guide_jdk_providers JDK Providers}43* document for information on the KeyPairGenerator defaults used by44* JDK providers.45* However, note that defaults may vary across different providers.46* Additionally, the default value for a provider may change in a future47* version. Therefore, it is recommended to explicitly initialize the48* KeyPairGenerator instead of relying on provider-specific defaults.49*50* @author Benjamin Renaud51* @since 1.252*53*54* @see KeyPairGenerator55* @see java.security.spec.AlgorithmParameterSpec56*/5758public abstract class KeyPairGeneratorSpi {5960/**61* Constructor for subclasses to call.62*/63public KeyPairGeneratorSpi() {}6465/**66* Initializes the key pair generator for a certain keysize, using67* the default parameter set.68*69* @param keysize the keysize. This is an70* algorithm-specific metric, such as modulus length, specified in71* number of bits.72*73* @param random the source of randomness for this generator.74*75* @throws InvalidParameterException if the {@code keysize} is not76* supported by this KeyPairGeneratorSpi object.77*/78public abstract void initialize(int keysize, SecureRandom random);7980/**81* Initializes the key pair generator using the specified parameter82* set and user-provided source of randomness.83*84* <p>This concrete method has been added to this previously-defined85* abstract class. (For backwards compatibility, it cannot be abstract.)86* It may be overridden by a provider to initialize the key pair87* generator. Such an override88* is expected to throw an InvalidAlgorithmParameterException if89* a parameter is inappropriate for this key pair generator.90* If this method is not overridden, it always throws an91* UnsupportedOperationException.92*93* @param params the parameter set used to generate the keys.94*95* @param random the source of randomness for this generator.96*97* @throws InvalidAlgorithmParameterException if the given parameters98* are inappropriate for this key pair generator.99*100* @since 1.2101*/102public void initialize(AlgorithmParameterSpec params,103SecureRandom random)104throws InvalidAlgorithmParameterException {105throw new UnsupportedOperationException();106}107108/**109* Generates a key pair. Unless an initialization method is called110* using a KeyPairGenerator interface, algorithm-specific defaults111* will be used. This will generate a new key pair every time it112* is called.113*114* @return the newly generated {@code KeyPair}115*/116public abstract KeyPair generateKeyPair();117}118119120