History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/java/security/KeyFactorySpi.java (1 of 18352 files). Show all

Unified · Split

java/pkg/java/security/KeyFactorySpi.java+140−0
@@ -0,0 +1,140 @@
1+/*
2+ * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle in the LICENSE file that accompanied this code.
10+ *
11+ * This code is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+ * version 2 for more details (a copy is included in the LICENSE file that
15+ * accompanied this code).
16+ *
17+ * You should have received a copy of the GNU General Public License version
18+ * 2 along with this work; if not, write to the Free Software Foundation,
19+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+ *
21+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package java.security;
27+
28+import java.security.spec.KeySpec;
29+import java.security.spec.InvalidKeySpecException;
30+
31+/**
32+ * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
33+ * for the <code>KeyFactory</code> class.
34+ * All the abstract methods in this class must be implemented by each
35+ * cryptographic service provider who wishes to supply the implementation
36+ * of a key factory for a particular algorithm.
37+ *
38+ * <P> Key factories are used to convert <I>keys</I> (opaque
39+ * cryptographic keys of type <code>Key</code>) into <I>key specifications</I>
40+ * (transparent representations of the underlying key material), and vice
41+ * versa.
42+ *
43+ * <P> Key factories are bi-directional. That is, they allow you to build an
44+ * opaque key object from a given key specification (key material), or to
45+ * retrieve the underlying key material of a key object in a suitable format.
46+ *
47+ * <P> Multiple compatible key specifications may exist for the same key.
48+ * For example, a DSA public key may be specified using
49+ * <code>DSAPublicKeySpec</code> or
50+ * <code>X509EncodedKeySpec</code>. A key factory can be used to translate
51+ * between compatible key specifications.
52+ *
53+ * <P> A provider should document all the key specifications supported by its
54+ * key factory.
55+ *
56+ * @author Jan Luehe
57+ *
58+ *
59+ * @see KeyFactory
60+ * @see Key
61+ * @see PublicKey
62+ * @see PrivateKey
63+ * @see java.security.spec.KeySpec
64+ * @see java.security.spec.DSAPublicKeySpec
65+ * @see java.security.spec.X509EncodedKeySpec
66+ *
67+ * @since 1.2
68+ */
69+
70+public abstract class KeyFactorySpi {
71+
72+ /**
73+ * Generates a public key object from the provided key
74+ * specification (key material).
75+ *
76+ * @param keySpec the specification (key material) of the public key.
77+ *
78+ * @return the public key.
79+ *
80+ * @exception InvalidKeySpecException if the given key specification
81+ * is inappropriate for this key factory to produce a public key.
82+ */
83+ protected abstract PublicKey engineGeneratePublic(KeySpec keySpec)
84+ throws InvalidKeySpecException;
85+
86+ /**
87+ * Generates a private key object from the provided key
88+ * specification (key material).
89+ *
90+ * @param keySpec the specification (key material) of the private key.
91+ *
92+ * @return the private key.
93+ *
94+ * @exception InvalidKeySpecException if the given key specification
95+ * is inappropriate for this key factory to produce a private key.
96+ */
97+ protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec)
98+ throws InvalidKeySpecException;
99+
100+ /**
101+ * Returns a specification (key material) of the given key
102+ * object.
103+ * <code>keySpec</code> identifies the specification class in which
104+ * the key material should be returned. It could, for example, be
105+ * <code>DSAPublicKeySpec.class</code>, to indicate that the
106+ * key material should be returned in an instance of the
107+ * <code>DSAPublicKeySpec</code> class.
108+ *
109+ * @param key the key.
110+ *
111+ * @param keySpec the specification class in which
112+ * the key material should be returned.
113+ *
114+ * @return the underlying key specification (key material) in an instance
115+ * of the requested specification class.
116+
117+ * @exception InvalidKeySpecException if the requested key specification is
118+ * inappropriate for the given key, or the given key cannot be dealt with
119+ * (e.g., the given key has an unrecognized format).
120+ */
121+ protected abstract <T extends KeySpec>
122+ T engineGetKeySpec(Key key, Class<T> keySpec)
123+ throws InvalidKeySpecException;
124+
125+ /**
126+ * Translates a key object, whose provider may be unknown or
127+ * potentially untrusted, into a corresponding key object of this key
128+ * factory.
129+ *
130+ * @param key the key whose provider is unknown or untrusted.
131+ *
132+ * @return the translated key.
133+ *
134+ * @exception InvalidKeyException if the given key cannot be processed
135+ * by this key factory.
136+ */
137+ protected abstract Key engineTranslateKey(Key key)
138+ throws InvalidKeyException;
139+
140+}