1. /*
  2. * @(#)Key.java 1.54 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security;
  8. /**
  9. * The Key interface is the top-level interface for all keys. It
  10. * defines the functionality shared by all key objects. All keys
  11. * have three characteristics:
  12. *
  13. * <UL>
  14. *
  15. * <LI>An Algorithm
  16. *
  17. * <P>This is the key algorithm for that key. The key algorithm is usually
  18. * an encryption or asymmetric operation algorithm (such as DSA or
  19. * RSA), which will work with those algorithms and with related
  20. * algorithms (such as MD5 with RSA, SHA-1 with RSA, Raw DSA, etc.)
  21. * The name of the algorithm of a key is obtained using the
  22. * {@link #getAlgorithm() getAlgorithm} method.<P>
  23. *
  24. * <LI>An Encoded Form
  25. *
  26. * <P>This is an external encoded form for the key used when a standard
  27. * representation of the key is needed outside the Java Virtual Machine,
  28. * as when transmitting the key to some other party. The key
  29. * is encoded according to a standard format (such as
  30. * X.509 <code>SubjectPublicKeyInfo</code> or PKCS#8), and
  31. * is returned using the {@link #getEncoded() getEncoded} method.
  32. * Note: The syntax of the ASN.1 type <code>SubjectPublicKeyInfo</code>
  33. * is defined as follows:
  34. *
  35. * <pre>
  36. * SubjectPublicKeyInfo ::= SEQUENCE {
  37. * algorithm AlgorithmIdentifier,
  38. * subjectPublicKey BIT STRING }
  39. *
  40. * AlgorithmIdentifier ::= SEQUENCE {
  41. * algorithm OBJECT IDENTIFIER,
  42. * parameters ANY DEFINED BY algorithm OPTIONAL }
  43. * </pre>
  44. *
  45. * For more information, see
  46. * <a href="http://www.ietf.org/rfc/rfc2459.txt">RFC 2459:
  47. * Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>.
  48. * <P>
  49. *
  50. * <LI>A Format
  51. *
  52. * <P>This is the name of the format of the encoded key. It is returned
  53. * by the {@link #getFormat() getFormat} method.<P>
  54. *
  55. * </UL>
  56. *
  57. * Keys are generally obtained through key generators, certificates,
  58. * or various Identity classes used to manage keys.
  59. * Keys may also be obtained from key specifications (transparent
  60. * representations of the underlying key material) through the use of a key
  61. * factory (see {@link KeyFactory}).
  62. *
  63. * <p> A Key should use KeyRep as its serialized representation.
  64. * Note that a serialized Key may contain sensitive information
  65. * which should not be exposed in untrusted environments. See the
  66. * <a href="../../../guide/serialization/spec/security.html">
  67. * Security Appendix</a>
  68. * of the Serialization Specification for more information.
  69. *
  70. * @see PublicKey
  71. * @see PrivateKey
  72. * @see KeyPair
  73. * @see KeyPairGenerator
  74. * @see KeyFactory
  75. * @see KeyRep
  76. * @see java.security.spec.KeySpec
  77. * @see Identity
  78. * @see Signer
  79. *
  80. * @version 1.54 03/12/19
  81. * @author Benjamin Renaud
  82. */
  83. public interface Key extends java.io.Serializable {
  84. // Declare serialVersionUID to be compatible with JDK1.1
  85. /**
  86. * The class fingerprint that is set to indicate
  87. * serialization compatibility with a previous
  88. * version of the class.
  89. */
  90. static final long serialVersionUID = 6603384152749567654L;
  91. /**
  92. * Returns the standard algorithm name for this key. For
  93. * example, "DSA" would indicate that this key is a DSA key.
  94. * See Appendix A in the <a href=
  95. * "../../../guide/security/CryptoSpec.html#AppA">
  96. * Java Cryptography Architecture API Specification & Reference </a>
  97. * for information about standard algorithm names.
  98. *
  99. * @return the name of the algorithm associated with this key.
  100. */
  101. public String getAlgorithm();
  102. /**
  103. * Returns the name of the primary encoding format of this key,
  104. * or null if this key does not support encoding.
  105. * The primary encoding format is
  106. * named in terms of the appropriate ASN.1 data format, if an
  107. * ASN.1 specification for this key exists.
  108. * For example, the name of the ASN.1 data format for public
  109. * keys is <I>SubjectPublicKeyInfo</I>, as
  110. * defined by the X.509 standard; in this case, the returned format is
  111. * <code>"X.509"</code>. Similarly,
  112. * the name of the ASN.1 data format for private keys is
  113. * <I>PrivateKeyInfo</I>,
  114. * as defined by the PKCS #8 standard; in this case, the returned format is
  115. * <code>"PKCS#8"</code>.
  116. *
  117. * @return the primary encoding format of the key.
  118. */
  119. public String getFormat();
  120. /**
  121. * Returns the key in its primary encoding format, or null
  122. * if this key does not support encoding.
  123. *
  124. * @return the encoded key, or null if the key does not support
  125. * encoding.
  126. */
  127. public byte[] getEncoded();
  128. }