Path: blob/master/src/java.base/share/classes/javax/crypto/KeyGeneratorSpi.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 javax.crypto;2627import java.security.*;28import java.security.spec.*;2930/**31* This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)32* for the <code>KeyGenerator</code> class.33* All the abstract methods in this class must be implemented by each34* cryptographic service provider who wishes to supply the implementation35* of a key generator for a particular algorithm.36*37* <p>In case the client does not explicitly initialize the KeyGenerator38* (via a call to an {@code init} method), each provider must39* supply (and document) a default initialization.40* See the Keysize Restriction sections of the41* {@extLink security_guide_jdk_providers JDK Providers}42* document for information on the KeyGenerator defaults used by43* JDK providers.44* However, note that defaults may vary across different providers.45* Additionally, the default value for a provider may change in a future46* version. Therefore, it is recommended to explicitly initialize the47* KeyGenerator instead of relying on provider-specific defaults.48*49* @author Jan Luehe50*51* @see SecretKey52* @since 1.453*/5455public abstract class KeyGeneratorSpi {5657/**58* Constructor for subclasses to call.59*/60public KeyGeneratorSpi() {}6162/**63* Initializes the key generator.64*65* @param random the source of randomness for this generator66*/67protected abstract void engineInit(SecureRandom random);6869/**70* Initializes the key generator with the specified parameter71* set and a user-provided source of randomness.72*73* @param params the key generation parameters74* @param random the source of randomness for this key generator75*76* @exception InvalidAlgorithmParameterException if <code>params</code> is77* inappropriate for this key generator78*/79protected abstract void engineInit(AlgorithmParameterSpec params,80SecureRandom random)81throws InvalidAlgorithmParameterException;8283/**84* Initializes this key generator for a certain keysize, using the given85* source of randomness.86*87* @param keysize the keysize. This is an algorithm-specific metric,88* specified in number of bits.89* @param random the source of randomness for this key generator90*91* @exception InvalidParameterException if the keysize is wrong or not92* supported.93*/94protected abstract void engineInit(int keysize, SecureRandom random);9596/**97* Generates a secret key.98*99* @return the new key100*/101protected abstract SecretKey engineGenerateKey();102}103104105