KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > KeyFactorySpi


1 /*
2  * @(#)KeyFactorySpi.java 1.12 04/05/05
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.KeySpec JavaDoc;
11 import java.security.spec.InvalidKeySpecException JavaDoc;
12
13 /**
14  * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
15  * for the <code>KeyFactory</code> class.
16  * All the abstract methods in this class must be implemented by each
17  * cryptographic service provider who wishes to supply the implementation
18  * of a key factory for a particular algorithm.
19  *
20  * <P> Key factories are used to convert <I>keys</I> (opaque
21  * cryptographic keys of type <code>Key</code>) into <I>key specifications</I>
22  * (transparent representations of the underlying key material), and vice
23  * versa.
24  *
25  * <P> Key factories are bi-directional. That is, they allow you to build an
26  * opaque key object from a given key specification (key material), or to
27  * retrieve the underlying key material of a key object in a suitable format.
28  *
29  * <P> Multiple compatible key specifications may exist for the same key.
30  * For example, a DSA public key may be specified using
31  * <code>DSAPublicKeySpec</code> or
32  * <code>X509EncodedKeySpec</code>. A key factory can be used to translate
33  * between compatible key specifications.
34  *
35  * <P> A provider should document all the key specifications supported by its
36  * key factory.
37  *
38  * @author Jan Luehe
39  *
40  * @version 1.12, 05/05/04
41  *
42  * @see KeyFactory
43  * @see Key
44  * @see PublicKey
45  * @see PrivateKey
46  * @see java.security.spec.KeySpec
47  * @see java.security.spec.DSAPublicKeySpec
48  * @see java.security.spec.X509EncodedKeySpec
49  *
50  * @since 1.2
51  */

52
53 public abstract class KeyFactorySpi {
54
55     /**
56      * Generates a public key object from the provided key
57      * specification (key material).
58      *
59      * @param keySpec the specification (key material) of the public key.
60      *
61      * @return the public key.
62      *
63      * @exception InvalidKeySpecException if the given key specification
64      * is inappropriate for this key factory to produce a public key.
65      */

66     protected abstract PublicKey JavaDoc engineGeneratePublic(KeySpec JavaDoc keySpec)
67         throws InvalidKeySpecException JavaDoc;
68
69     /**
70      * Generates a private key object from the provided key
71      * specification (key material).
72      *
73      * @param keySpec the specification (key material) of the private key.
74      *
75      * @return the private key.
76      *
77      * @exception InvalidKeySpecException if the given key specification
78      * is inappropriate for this key factory to produce a private key.
79      */

80     protected abstract PrivateKey JavaDoc engineGeneratePrivate(KeySpec JavaDoc keySpec)
81         throws InvalidKeySpecException JavaDoc;
82
83     /**
84      * Returns a specification (key material) of the given key
85      * object.
86      * <code>keySpec</code> identifies the specification class in which
87      * the key material should be returned. It could, for example, be
88      * <code>DSAPublicKeySpec.class</code>, to indicate that the
89      * key material should be returned in an instance of the
90      * <code>DSAPublicKeySpec</code> class.
91      *
92      * @param key the key.
93      *
94      * @param keySpec the specification class in which
95      * the key material should be returned.
96      *
97      * @return the underlying key specification (key material) in an instance
98      * of the requested specification class.
99
100      * @exception InvalidKeySpecException if the requested key specification is
101      * inappropriate for the given key, or the given key cannot be dealt with
102      * (e.g., the given key has an unrecognized format).
103      */

104     protected abstract <T extends KeySpec JavaDoc>
105     T engineGetKeySpec(Key JavaDoc key, Class JavaDoc<T> keySpec)
106     throws InvalidKeySpecException JavaDoc;
107
108     /**
109      * Translates a key object, whose provider may be unknown or
110      * potentially untrusted, into a corresponding key object of this key
111      * factory.
112      *
113      * @param key the key whose provider is unknown or untrusted.
114      *
115      * @return the translated key.
116      *
117      * @exception InvalidKeyException if the given key cannot be processed
118      * by this key factory.
119      */

120     protected abstract Key JavaDoc engineTranslateKey(Key JavaDoc key)
121     throws InvalidKeyException JavaDoc;
122
123 }
124
Popular Tags