KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > KeyPairGeneratorSpi


1 /*
2  * @(#)KeyPairGeneratorSpi.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7  
8 package java.security;
9
10 import java.security.spec.AlgorithmParameterSpec JavaDoc;
11
12 /**
13  * <p> This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
14  * for the <code>KeyPairGenerator</code> class, which is used to generate
15  * pairs of public and private keys.
16  *
17  * <p> All the abstract methods in this class must be implemented by each
18  * cryptographic service provider who wishes to supply the implementation
19  * of a key pair generator for a particular algorithm.
20  *
21  * <p> In case the client does not explicitly initialize the KeyPairGenerator
22  * (via a call to an <code>initialize</code> method), each provider must
23  * supply (and document) a default initialization.
24  * For example, the <i>Sun</i> provider uses a default modulus size (keysize)
25  * of 1024 bits.
26  *
27  * @author Benjamin Renaud
28  *
29  * @version 1.14, 12/19/03
30  *
31  * @see KeyPairGenerator
32  * @see java.security.spec.AlgorithmParameterSpec
33  */

34
35 public abstract class KeyPairGeneratorSpi {
36
37     /**
38      * Initializes the key pair generator for a certain keysize, using
39      * the default parameter set.
40      *
41      * @param keysize the keysize. This is an
42      * algorithm-specific metric, such as modulus length, specified in
43      * number of bits.
44      *
45      * @param random the source of randomness for this generator.
46      *
47      * @exception InvalidParameterException if the <code>keysize</code> is not
48      * supported by this KeyPairGeneratorSpi object.
49      */

50     public abstract void initialize(int keysize, SecureRandom JavaDoc random);
51
52     /**
53      * Initializes the key pair generator using the specified parameter
54      * set and user-provided source of randomness.
55      *
56      * <p>This concrete method has been added to this previously-defined
57      * abstract class. (For backwards compatibility, it cannot be abstract.)
58      * It may be overridden by a provider to initialize the key pair
59      * generator. Such an override
60      * is expected to throw an InvalidAlgorithmParameterException if
61      * a parameter is inappropriate for this key pair generator.
62      * If this method is not overridden, it always throws an
63      * UnsupportedOperationException.
64      *
65      * @param params the parameter set used to generate the keys.
66      *
67      * @param random the source of randomness for this generator.
68      *
69      * @exception InvalidAlgorithmParameterException if the given parameters
70      * are inappropriate for this key pair generator.
71      *
72      * @since 1.2
73      */

74     public void initialize(AlgorithmParameterSpec JavaDoc params,
75                    SecureRandom JavaDoc random)
76     throws InvalidAlgorithmParameterException JavaDoc {
77         throw new UnsupportedOperationException JavaDoc();
78     }
79
80     /**
81      * Generates a key pair. Unless an initialization method is called
82      * using a KeyPairGenerator interface, algorithm-specific defaults
83      * will be used. This will generate a new key pair every time it
84      * is called.
85      *
86      * @return the newly generated <tt>KeyPair</tt>
87      */

88     public abstract KeyPair JavaDoc generateKeyPair();
89 }
90
Popular Tags