1. /*
  2. * @(#)KeyPair.java 1.15 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. 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.15 03/12/19
  18. * @author Benjamin Renaud
  19. */
  20. public final class KeyPair implements java.io.Serializable {
  21. private static final long serialVersionUID = -7565189502268009837L;
  22. private PrivateKey privateKey;
  23. private PublicKey publicKey;
  24. /**
  25. * Constructs a key pair from the given public key and private key.
  26. *
  27. * <p>Note that this constructor only stores references to the public
  28. * and private key components in the generated key pair. This is safe,
  29. * because <code>Key</code> objects are immutable.
  30. *
  31. * @param publicKey the public key.
  32. *
  33. * @param privateKey the private key.
  34. */
  35. public KeyPair(PublicKey publicKey, PrivateKey privateKey) {
  36. this.publicKey = publicKey;
  37. this.privateKey = privateKey;
  38. }
  39. /**
  40. * Returns a reference to the public key component of this key pair.
  41. *
  42. * @return a reference to the public key.
  43. */
  44. public PublicKey getPublic() {
  45. return publicKey;
  46. }
  47. /**
  48. * Returns a reference to the private key component of this key pair.
  49. *
  50. * @return a reference to the private key.
  51. */
  52. public PrivateKey getPrivate() {
  53. return privateKey;
  54. }
  55. }