1 module hunt.security.Key; 2 3 /** 4 * The Key interface is the top-level interface for all keys. It 5 * defines the functionality shared by all key objects. All keys 6 * have three characteristics: 7 * 8 * <UL> 9 * 10 * <LI>An Algorithm 11 * 12 * <P>This is the key algorithm for that key. The key algorithm is usually 13 * an encryption or asymmetric operation algorithm (such as DSA or 14 * RSA), which will work with those algorithms and with related 15 * algorithms (such as MD5 with RSA, SHA-1 with RSA, Raw DSA, etc.) 16 * The name of the algorithm of a key is obtained using the 17 * {@link #getAlgorithm() getAlgorithm} method. 18 * 19 * <LI>An Encoded Form 20 * 21 * <P>This is an external encoded form for the key used when a standard 22 * representation of the key is needed outside the Java Virtual Machine, 23 * as when transmitting the key to some other party. The key 24 * is encoded according to a standard format (such as 25 * X.509 {@code SubjectPublicKeyInfo} or PKCS#8), and 26 * is returned using the {@link #getEncoded() getEncoded} method. 27 * Note: The syntax of the ASN.1 type {@code SubjectPublicKeyInfo} 28 * is defined as follows: 29 * 30 * <pre> 31 * SubjectPublicKeyInfo ::= SEQUENCE { 32 * algorithm AlgorithmIdentifier, 33 * subjectPublicKey BIT STRING } 34 * 35 * AlgorithmIdentifier ::= SEQUENCE { 36 * algorithm OBJECT IDENTIFIER, 37 * parameters ANY DEFINED BY algorithm OPTIONAL } 38 * </pre> 39 * 40 * For more information, see 41 * <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: 42 * Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>. 43 * 44 * <LI>A Format 45 * 46 * <P>This is the name of the format of the encoded key. It is returned 47 * by the {@link #getFormat() getFormat} method. 48 * 49 * </UL> 50 * 51 * Keys are generally obtained through key generators, certificates, 52 * or various Identity classes used to manage keys. 53 * Keys may also be obtained from key specifications (transparent 54 * representations of the underlying key material) through the use of a key 55 * factory (see {@link KeyFactory}). 56 * 57 * <p> A Key should use KeyRep as its serialized representation. 58 * Note that a serialized Key may contain sensitive information 59 * which should not be exposed in untrusted environments. See the 60 * <a href="../../../platform/serialization/spec/security.html"> 61 * Security Appendix</a> 62 * of the Serialization Specification for more information. 63 * 64 * @see PublicKey 65 * @see PrivateKey 66 * @see KeyPair 67 * @see KeyPairGenerator 68 * @see KeyFactory 69 * @see KeyRep 70 * @see java.security.spec.KeySpec 71 * @see Identity 72 * @see Signer 73 * 74 * @author Benjamin Renaud 75 */ 76 77 interface Key { 78 79 // Declare serialVersionUID to be compatible with JDK1.1 80 81 /** 82 * The class fingerprint that is set to indicate 83 * serialization compatibility with a previous 84 * version of the class. 85 */ 86 // enum long serialVersionUID = 6603384152749567654L; 87 88 /** 89 * Returns the standard algorithm name for this key. For 90 * example, "DSA" would indicate that this key is a DSA key. 91 * See Appendix A in the <a href= 92 * "../../../technotes/guides/security/crypto/CryptoSpec.html#AppA"> 93 * Java Cryptography Architecture API Specification & Reference </a> 94 * for information about standard algorithm names. 95 * 96 * @return the name of the algorithm associated with this key. 97 */ 98 string getAlgorithm(); 99 100 /** 101 * Returns the name of the primary encoding format of this key, 102 * or null if this key does not support encoding. 103 * The primary encoding format is 104 * named in terms of the appropriate ASN.1 data format, if an 105 * ASN.1 specification for this key exists. 106 * For example, the name of the ASN.1 data format for public 107 * keys is <I>SubjectPublicKeyInfo</I>, as 108 * defined by the X.509 standard; in this case, the returned format is 109 * {@code "X.509"}. Similarly, 110 * the name of the ASN.1 data format for private keys is 111 * <I>PrivateKeyInfo</I>, 112 * as defined by the PKCS #8 standard; in this case, the returned format is 113 * {@code "PKCS#8"}. 114 * 115 * @return the primary encoding format of the key. 116 */ 117 string getFormat(); 118 119 /** 120 * Returns the key in its primary encoding format, or null 121 * if this key does not support encoding. 122 * 123 * @return the encoded key, or null if the key does not support 124 * encoding. 125 */ 126 byte[] getEncoded(); 127 } 128 129 130 131 /** 132 * A private key. 133 * The purpose of this interface is to group (and provide type safety 134 * for) all private key interfaces. 135 * <p> 136 * Note: The specialized private key interfaces extend this interface. 137 * See, for example, the {@code DSAPrivateKey} interface in 138 * {@link java.security.interfaces}. 139 * <p> 140 * Implementations should override the default {@code destroy} and 141 * {@code isDestroyed} methods from the 142 * {@link javax.security.auth.Destroyable} interface to enable 143 * sensitive key information to be destroyed, cleared, or in the case 144 * where such information is immutable, unreferenced. 145 * Finally, since {@code PrivateKey} is {@code Serializable}, implementations 146 * should also override 147 * {@link java.io.ObjectOutputStream#writeObject(java.lang.Object)} 148 * to prevent keys that have been destroyed from being serialized. 149 * 150 * @see Key 151 * @see PublicKey 152 * @see Certificate 153 * @see Signature#initVerify 154 * @see java.security.interfaces.DSAPrivateKey 155 * @see java.security.interfaces.RSAPrivateKey 156 * @see java.security.interfaces.RSAPrivateCrtKey 157 * 158 * @author Benjamin Renaud 159 * @author Josh Bloch 160 */ 161 162 interface PrivateKey : Key { 163 164 // Declare serialVersionUID to be compatible with JDK1.1 165 /** 166 * The class fingerprint that is set to indicate serialization 167 * compatibility with a previous version of the class. 168 */ 169 // static final long serialVersionUID = 6034044314589513430L; 170 } 171 172 173 /** 174 * <p>A public key. This interface contains no methods or constants. 175 * It merely serves to group (and provide type safety for) all public key 176 * interfaces. 177 * 178 * Note: The specialized public key interfaces extend this interface. 179 * See, for example, the DSAPublicKey interface in 180 * {@code java.security.interfaces}. 181 * 182 * @see Key 183 * @see PrivateKey 184 * @see Certificate 185 * @see Signature#initVerify 186 * @see java.security.interfaces.DSAPublicKey 187 * @see java.security.interfaces.RSAPublicKey 188 * 189 */ 190 191 interface PublicKey : Key { 192 // Declare serialVersionUID to be compatible with JDK1.1 193 /** 194 * The class fingerprint that is set to indicate serialization 195 * compatibility with a previous version of the class. 196 */ 197 // static final long serialVersionUID = 7187392471159151072L; 198 } 199