1. /*
  2. * @(#)KeyPair.java 1.13 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. import java.util.*;
  9. /**
  10. * This class is a simple holder for a key pair (a public key and a
  11. * private key). It does not enforce any security, and, when initialized,
  12. * should be treated like a PrivateKey.
  13. *
  14. * @see PublicKey
  15. * @see PrivateKey
  16. *
  17. * @version 1.13 03/01/23
  18. * @author Benjamin Renaud
  19. */
  20. public final class KeyPair implements java.io.Serializable {
  21. private PrivateKey privateKey;
  22. private PublicKey publicKey;
  23. /**
  24. * Constructs a key pair from the given public key and private key.
  25. *
  26. * <p>Note that this constructor only stores references to the public
  27. * and private key components in the generated key pair. This is safe,
  28. * because <code>Key</code> objects are immutable.
  29. *
  30. * @param publicKey the public key.
  31. *
  32. * @param privateKey the private key.
  33. */
  34. public KeyPair(PublicKey publicKey, PrivateKey privateKey) {
  35. this.publicKey = publicKey;
  36. this.privateKey = privateKey;
  37. }
  38. /**
  39. * Returns a reference to the public key component of this key pair.
  40. *
  41. * @return a reference to the public key.
  42. */
  43. public PublicKey getPublic() {
  44. return publicKey;
  45. }
  46. /**
  47. * Returns a reference to the private key component of this key pair.
  48. *
  49. * @return a reference to the private key.
  50. */
  51. public PrivateKey getPrivate() {
  52. return privateKey;
  53. }
  54. }