1. /*
  2. * @(#)Key.java 1.44 01/11/29
  3. *
  4. * Copyright 2002 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 X.509 or PKCS#8), and
  30. * is returned using the {@link getEncoded() getEncoded} method.<P>
  31. *
  32. * <LI>A Format
  33. *
  34. * <P>This is the name of the format of the encoded key. It is returned
  35. * by the {@link getFormat() getFormat} method.<P>
  36. *
  37. * </UL>
  38. *
  39. * Keys are generally obtained through key generators, certificates,
  40. * or various Identity classes used to manage keys.
  41. * Keys may also be obtained from key specifications (transparent
  42. * representations of the underlying key material) through the use of a key
  43. * factory (see {@link KeyFactory}).
  44. *
  45. * @see PublicKey
  46. * @see PrivateKey
  47. * @see KeyPair
  48. * @see KeyPairGenerator
  49. * @see KeyFactory
  50. * @see java.security.spec.KeySpec
  51. * @see Identity
  52. * @see Signer
  53. *
  54. * @version 1.44 01/11/29
  55. * @author Benjamin Renaud
  56. */
  57. public interface Key extends java.io.Serializable {
  58. // Declare serialVersionUID to be compatible with JDK1.1
  59. static final long serialVersionUID = 6603384152749567654L;
  60. /**
  61. * Returns the standard algorithm name for this key. For
  62. * example, "DSA" would indicate that this key is a DSA key.
  63. * See Appendix A in the <a href=
  64. * "../../../guide/security/CryptoSpec.html#AppA">
  65. * Java Cryptography Architecture API Specification & Reference </a>
  66. * for information about standard algorithm names.
  67. *
  68. * @return the name of the algorithm associated with this key.
  69. */
  70. public String getAlgorithm();
  71. /**
  72. * Returns the name of the primary encoding format of this key,
  73. * or null if this key does not support encoding.
  74. * The primary encoding format is
  75. * named in terms of the appropriate ASN.1 data format, if an
  76. * ASN.1 specification for this key exists.
  77. * For example, the name of the ASN.1 data format for public
  78. * keys is <I>SubjectPublicKeyInfo</I>, as
  79. * defined by the X.509 standard; in this case, the returned format is
  80. * <code>"X.509"</code>. Similarly,
  81. * the name of the ASN.1 data format for private keys is
  82. * <I>PrivateKeyInfo</I>,
  83. * as defined by the PKCS #8 standard; in this case, the returned format is
  84. * <code>"PKCS#8"</code>.
  85. *
  86. * @return the primary encoding format of the key.
  87. */
  88. public String getFormat();
  89. /**
  90. * Returns the key in its primary encoding format, or null
  91. * if this key does not support encoding.
  92. *
  93. * @return the encoded key, or null if the key does not support
  94. * encoding.
  95. */
  96. public byte[] getEncoded();
  97. }