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