1. /*
  2. * @(#)Key.java 1.52 03/01/23
  3. *
  4. * Copyright 2003 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. * @see PublicKey
  64. * @see PrivateKey
  65. * @see KeyPair
  66. * @see KeyPairGenerator
  67. * @see KeyFactory
  68. * @see java.security.spec.KeySpec
  69. * @see Identity
  70. * @see Signer
  71. *
  72. * @version 1.52 03/01/23
  73. * @author Benjamin Renaud
  74. */
  75. public interface Key extends java.io.Serializable {
  76. // Declare serialVersionUID to be compatible with JDK1.1
  77. /**
  78. * The class fingerprint that is set to indicate
  79. * serialization compatibility with a previous
  80. * version of the class.
  81. */
  82. static final long serialVersionUID = 6603384152749567654L;
  83. /**
  84. * Returns the standard algorithm name for this key. For
  85. * example, "DSA" would indicate that this key is a DSA key.
  86. * See Appendix A in the <a href=
  87. * "../../../guide/security/CryptoSpec.html#AppA">
  88. * Java Cryptography Architecture API Specification & Reference </a>
  89. * for information about standard algorithm names.
  90. *
  91. * @return the name of the algorithm associated with this key.
  92. */
  93. public String getAlgorithm();
  94. /**
  95. * Returns the name of the primary encoding format of this key,
  96. * or null if this key does not support encoding.
  97. * The primary encoding format is
  98. * named in terms of the appropriate ASN.1 data format, if an
  99. * ASN.1 specification for this key exists.
  100. * For example, the name of the ASN.1 data format for public
  101. * keys is <I>SubjectPublicKeyInfo</I>, as
  102. * defined by the X.509 standard; in this case, the returned format is
  103. * <code>"X.509"</code>. Similarly,
  104. * the name of the ASN.1 data format for private keys is
  105. * <I>PrivateKeyInfo</I>,
  106. * as defined by the PKCS #8 standard; in this case, the returned format is
  107. * <code>"PKCS#8"</code>.
  108. *
  109. * @return the primary encoding format of the key.
  110. */
  111. public String getFormat();
  112. /**
  113. * Returns the key in its primary encoding format, or null
  114. * if this key does not support encoding.
  115. *
  116. * @return the encoded key, or null if the key does not support
  117. * encoding.
  118. */
  119. public byte[] getEncoded();
  120. }