1. /*
  2. * @(#)Key.java 1.47 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.security;
  11. /**
  12. * The Key interface is the top-level interface for all keys. It
  13. * defines the functionality shared by all key objects. All keys
  14. * have three characteristics:
  15. *
  16. * <UL>
  17. *
  18. * <LI>An Algorithm
  19. *
  20. * <P>This is the key algorithm for that key. The key algorithm is usually
  21. * an encryption or asymmetric operation algorithm (such as DSA or
  22. * RSA), which will work with those algorithms and with related
  23. * algorithms (such as MD5 with RSA, SHA-1 with RSA, Raw DSA, etc.)
  24. * The name of the algorithm of a key is obtained using the
  25. * {@link #getAlgorithm() getAlgorithm} method.<P>
  26. *
  27. * <LI>An Encoded Form
  28. *
  29. * <P>This is an external encoded form for the key used when a standard
  30. * representation of the key is needed outside the Java Virtual Machine,
  31. * as when transmitting the key to some other party. The key
  32. * is encoded according to a standard format (such as X.509 or PKCS#8), and
  33. * is returned using the {@link #getEncoded() getEncoded} method.<P>
  34. *
  35. * <LI>A Format
  36. *
  37. * <P>This is the name of the format of the encoded key. It is returned
  38. * by the {@link #getFormat() getFormat} method.<P>
  39. *
  40. * </UL>
  41. *
  42. * Keys are generally obtained through key generators, certificates,
  43. * or various Identity classes used to manage keys.
  44. * Keys may also be obtained from key specifications (transparent
  45. * representations of the underlying key material) through the use of a key
  46. * factory (see {@link KeyFactory}).
  47. *
  48. * @see PublicKey
  49. * @see PrivateKey
  50. * @see KeyPair
  51. * @see KeyPairGenerator
  52. * @see KeyFactory
  53. * @see java.security.spec.KeySpec
  54. * @see Identity
  55. * @see Signer
  56. *
  57. * @version 1.47 00/02/02
  58. * @author Benjamin Renaud
  59. */
  60. public interface Key extends java.io.Serializable {
  61. // Declare serialVersionUID to be compatible with JDK1.1
  62. /**
  63. * The class fingerprint that is set to indicate
  64. * serialization compatibility with a previous
  65. * version of the class.
  66. */
  67. static final long serialVersionUID = 6603384152749567654L;
  68. /**
  69. * Returns the standard algorithm name for this key. For
  70. * example, "DSA" would indicate that this key is a DSA key.
  71. * See Appendix A in the <a href=
  72. * "../../../guide/security/CryptoSpec.html#AppA">
  73. * Java Cryptography Architecture API Specification & Reference </a>
  74. * for information about standard algorithm names.
  75. *
  76. * @return the name of the algorithm associated with this key.
  77. */
  78. public String getAlgorithm();
  79. /**
  80. * Returns the name of the primary encoding format of this key,
  81. * or null if this key does not support encoding.
  82. * The primary encoding format is
  83. * named in terms of the appropriate ASN.1 data format, if an
  84. * ASN.1 specification for this key exists.
  85. * For example, the name of the ASN.1 data format for public
  86. * keys is <I>SubjectPublicKeyInfo</I>, as
  87. * defined by the X.509 standard; in this case, the returned format is
  88. * <code>"X.509"</code>. Similarly,
  89. * the name of the ASN.1 data format for private keys is
  90. * <I>PrivateKeyInfo</I>,
  91. * as defined by the PKCS #8 standard; in this case, the returned format is
  92. * <code>"PKCS#8"</code>.
  93. *
  94. * @return the primary encoding format of the key.
  95. */
  96. public String getFormat();
  97. /**
  98. * Returns the key in its primary encoding format, or null
  99. * if this key does not support encoding.
  100. *
  101. * @return the encoded key, or null if the key does not support
  102. * encoding.
  103. */
  104. public byte[] getEncoded();
  105. }