Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/security/Key.java
38829 views
/*1* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627/**28* The Key interface is the top-level interface for all keys. It29* defines the functionality shared by all key objects. All keys30* have three characteristics:31*32* <UL>33*34* <LI>An Algorithm35*36* <P>This is the key algorithm for that key. The key algorithm is usually37* an encryption or asymmetric operation algorithm (such as DSA or38* RSA), which will work with those algorithms and with related39* algorithms (such as MD5 with RSA, SHA-1 with RSA, Raw DSA, etc.)40* The name of the algorithm of a key is obtained using the41* {@link #getAlgorithm() getAlgorithm} method.42*43* <LI>An Encoded Form44*45* <P>This is an external encoded form for the key used when a standard46* representation of the key is needed outside the Java Virtual Machine,47* as when transmitting the key to some other party. The key48* is encoded according to a standard format (such as49* X.509 {@code SubjectPublicKeyInfo} or PKCS#8), and50* is returned using the {@link #getEncoded() getEncoded} method.51* Note: The syntax of the ASN.1 type {@code SubjectPublicKeyInfo}52* is defined as follows:53*54* <pre>55* SubjectPublicKeyInfo ::= SEQUENCE {56* algorithm AlgorithmIdentifier,57* subjectPublicKey BIT STRING }58*59* AlgorithmIdentifier ::= SEQUENCE {60* algorithm OBJECT IDENTIFIER,61* parameters ANY DEFINED BY algorithm OPTIONAL }62* </pre>63*64* For more information, see65* <a href="http://tools.ietf.org/html/rfc5280">RFC 5280:66* Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>.67*68* <LI>A Format69*70* <P>This is the name of the format of the encoded key. It is returned71* by the {@link #getFormat() getFormat} method.72*73* </UL>74*75* Keys are generally obtained through key generators, certificates,76* or various Identity classes used to manage keys.77* Keys may also be obtained from key specifications (transparent78* representations of the underlying key material) through the use of a key79* factory (see {@link KeyFactory}).80*81* <p> A Key should use KeyRep as its serialized representation.82* Note that a serialized Key may contain sensitive information83* which should not be exposed in untrusted environments. See the84* <a href="../../../platform/serialization/spec/security.html">85* Security Appendix</a>86* of the Serialization Specification for more information.87*88* @see PublicKey89* @see PrivateKey90* @see KeyPair91* @see KeyPairGenerator92* @see KeyFactory93* @see KeyRep94* @see java.security.spec.KeySpec95* @see Identity96* @see Signer97*98* @author Benjamin Renaud99*/100101public interface Key extends java.io.Serializable {102103// Declare serialVersionUID to be compatible with JDK1.1104105/**106* The class fingerprint that is set to indicate107* serialization compatibility with a previous108* version of the class.109*/110static final long serialVersionUID = 6603384152749567654L;111112/**113* Returns the standard algorithm name for this key. For114* example, "DSA" would indicate that this key is a DSA key.115* See Appendix A in the <a href=116* "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">117* Java Cryptography Architecture API Specification & Reference </a>118* for information about standard algorithm names.119*120* @return the name of the algorithm associated with this key.121*/122public String getAlgorithm();123124/**125* Returns the name of the primary encoding format of this key,126* or null if this key does not support encoding.127* The primary encoding format is128* named in terms of the appropriate ASN.1 data format, if an129* ASN.1 specification for this key exists.130* For example, the name of the ASN.1 data format for public131* keys is <I>SubjectPublicKeyInfo</I>, as132* defined by the X.509 standard; in this case, the returned format is133* {@code "X.509"}. Similarly,134* the name of the ASN.1 data format for private keys is135* <I>PrivateKeyInfo</I>,136* as defined by the PKCS #8 standard; in this case, the returned format is137* {@code "PKCS#8"}.138*139* @return the primary encoding format of the key.140*/141public String getFormat();142143/**144* Returns the key in its primary encoding format, or null145* if this key does not support encoding.146*147* @return the encoded key, or null if the key does not support148* encoding.149*/150public byte[] getEncoded();151}152153154