001 /*
002 * Copyright 1997-1999 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.security;
027
028 import java.security.spec.AlgorithmParameterSpec;
029
030 /**
031 * <p> This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
032 * for the <code>KeyPairGenerator</code> class, which is used to generate
033 * pairs of public and private keys.
034 *
035 * <p> All the abstract methods in this class must be implemented by each
036 * cryptographic service provider who wishes to supply the implementation
037 * of a key pair generator for a particular algorithm.
038 *
039 * <p> In case the client does not explicitly initialize the KeyPairGenerator
040 * (via a call to an <code>initialize</code> method), each provider must
041 * supply (and document) a default initialization.
042 * For example, the <i>Sun</i> provider uses a default modulus size (keysize)
043 * of 1024 bits.
044 *
045 * @author Benjamin Renaud
046 *
047 * @version 1.21, 05/05/07
048 *
049 * @see KeyPairGenerator
050 * @see java.security.spec.AlgorithmParameterSpec
051 */
052
053 public abstract class KeyPairGeneratorSpi {
054
055 /**
056 * Initializes the key pair generator for a certain keysize, using
057 * the default parameter set.
058 *
059 * @param keysize the keysize. This is an
060 * algorithm-specific metric, such as modulus length, specified in
061 * number of bits.
062 *
063 * @param random the source of randomness for this generator.
064 *
065 * @exception InvalidParameterException if the <code>keysize</code> is not
066 * supported by this KeyPairGeneratorSpi object.
067 */
068 public abstract void initialize(int keysize, SecureRandom random);
069
070 /**
071 * Initializes the key pair generator using the specified parameter
072 * set and user-provided source of randomness.
073 *
074 * <p>This concrete method has been added to this previously-defined
075 * abstract class. (For backwards compatibility, it cannot be abstract.)
076 * It may be overridden by a provider to initialize the key pair
077 * generator. Such an override
078 * is expected to throw an InvalidAlgorithmParameterException if
079 * a parameter is inappropriate for this key pair generator.
080 * If this method is not overridden, it always throws an
081 * UnsupportedOperationException.
082 *
083 * @param params the parameter set used to generate the keys.
084 *
085 * @param random the source of randomness for this generator.
086 *
087 * @exception InvalidAlgorithmParameterException if the given parameters
088 * are inappropriate for this key pair generator.
089 *
090 * @since 1.2
091 */
092 public void initialize(AlgorithmParameterSpec params,
093 SecureRandom random)
094 throws InvalidAlgorithmParameterException {
095 throw new UnsupportedOperationException();
096 }
097
098 /**
099 * Generates a key pair. Unless an initialization method is called
100 * using a KeyPairGenerator interface, algorithm-specific defaults
101 * will be used. This will generate a new key pair every time it
102 * is called.
103 *
104 * @return the newly generated <tt>KeyPair</tt>
105 */
106 public abstract KeyPair generateKeyPair();
107 }
|