01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package java.security;
28:
29: import com.sun.satsa.crypto.RSAPublicKey;
30: import java.security.spec.KeySpec;
31: import java.security.spec.InvalidKeySpecException;
32:
33: /**
34: * Key factories are used to convert <I>key specifications</I>
35: * (transparent representations of the underlying key material)
36: * into <I>keys</I> (opaque cryptographic keys of type <code>Key</code>).
37: *
38: *
39: *
40: * @version 1.28, 05/07/02
41: *
42: * @see Key
43: * @see PublicKey
44: * @see java.security.spec.KeySpec
45: * @see java.security.spec.X509EncodedKeySpec
46: *
47: * @since 1.2
48: */
49:
50: public class KeyFactory {
51: /**
52: * Creates a KeyFactory object.
53: */
54: KeyFactory() {
55: }
56:
57: /**
58: * Generates a KeyFactory object that implements the specified
59: * algorithm.
60: *
61: * @param algorithm the name of the requested key algorithm.
62: * See Appendix A in the
63: * Java Cryptography Architecture API Specification & Reference
64: * for information about standard algorithm names.
65: *
66: * @return a <code>KeyFactory</code> object for the specified algorithm.
67: *
68: * @exception NoSuchAlgorithmException if the requested algorithm is
69: * not available
70: */
71: public static KeyFactory getInstance(String algorithm)
72: throws NoSuchAlgorithmException {
73:
74: if (algorithm.toUpperCase().equals("RSA")) {
75: return new KeyFactory();
76: }
77: throw new NoSuchAlgorithmException();
78: }
79:
80: /**
81: * Generates a public key object from the provided key specification
82: * (key material).
83: *
84: * @param keySpec the specification (key material) of the public key.
85: *
86: * @return the public key.
87: *
88: * @exception InvalidKeySpecException if the given key specification
89: * is inappropriate for this key factory to produce a public key.
90: */
91: public final PublicKey generatePublic(KeySpec keySpec)
92: throws InvalidKeySpecException {
93: return new RSAPublicKey(keySpec);
94: }
95: }
|