jdk/src/java.base/share/classes/java/security/Key.java
author juh
Tue, 07 Oct 2014 22:23:19 -0700
changeset 26967 c182469301ee
parent 25859 3317bb8137f4
child 45138 ddcafe0d0ea3
permissions -rw-r--r--
8037550: Update RFC references in javadoc to RFC 5280 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The Key interface is the top-level interface for all keys. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * defines the functionality shared by all key objects. All keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * have three characteristics:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <LI>An Algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>This is the key algorithm for that key. The key algorithm is usually
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * an encryption or asymmetric operation algorithm (such as DSA or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * RSA), which will work with those algorithms and with related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * algorithms (such as MD5 with RSA, SHA-1 with RSA, Raw DSA, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The name of the algorithm of a key is obtained using the
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    42
 * {@link #getAlgorithm() getAlgorithm} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <LI>An Encoded Form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <P>This is an external encoded form for the key used when a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * representation of the key is needed outside the Java Virtual Machine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * as when transmitting the key to some other party. The key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * is encoded according to a standard format (such as
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    50
 * X.509 {@code SubjectPublicKeyInfo} or PKCS#8), and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * is returned using the {@link #getEncoded() getEncoded} method.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    52
 * Note: The syntax of the ASN.1 type {@code SubjectPublicKeyInfo}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * is defined as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * SubjectPublicKeyInfo ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   algorithm AlgorithmIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   subjectPublicKey BIT STRING }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * AlgorithmIdentifier ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *   algorithm OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   parameters ANY DEFINED BY algorithm OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * For more information, see
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
    66
 * <a href="http://tools.ietf.org/html/rfc5280">RFC 5280:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <LI>A Format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <P>This is the name of the format of the encoded key. It is returned
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18579
diff changeset
    72
 * by the {@link #getFormat() getFormat} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Keys are generally obtained through key generators, certificates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * or various Identity classes used to manage keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Keys may also be obtained from key specifications (transparent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * representations of the underlying key material) through the use of a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * factory (see {@link KeyFactory}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p> A Key should use KeyRep as its serialized representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * Note that a serialized Key may contain sensitive information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * which should not be exposed in untrusted environments.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <a href="../../../platform/serialization/spec/security.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Security Appendix</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * of the Serialization Specification for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see PublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see PrivateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @see KeyPair
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @see KeyPairGenerator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @see KeyFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @see KeyRep
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @see java.security.spec.KeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @see Identity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @see Signer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
public interface Key extends java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // Declare serialVersionUID to be compatible with JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    * The class fingerprint that is set to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    * serialization compatibility with a previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    * version of the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static final long serialVersionUID = 6603384152749567654L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returns the standard algorithm name for this key. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * example, "DSA" would indicate that this key is a DSA key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return the name of the algorithm associated with this key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Returns the name of the primary encoding format of this key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * or null if this key does not support encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * The primary encoding format is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * named in terms of the appropriate ASN.1 data format, if an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * ASN.1 specification for this key exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * For example, the name of the ASN.1 data format for public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * keys is <I>SubjectPublicKeyInfo</I>, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * defined by the X.509 standard; in this case, the returned format is
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   134
     * {@code "X.509"}. Similarly,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * the name of the ASN.1 data format for private keys is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <I>PrivateKeyInfo</I>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * as defined by the PKCS #8 standard; in this case, the returned format is
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   138
     * {@code "PKCS#8"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return the primary encoding format of the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public String getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns the key in its primary encoding format, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * if this key does not support encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return the encoded key, or null if the key does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public byte[] getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}