KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > KeyPair


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
8 package java.security;
9
10 import java.util.*;
11
12 /**
13  * This class is a simple holder for a key pair (a public key and a
14  * private key). It does not enforce any security, and, when initialized,
15  * should be treated like a PrivateKey.
16  *
17  * @see PublicKey
18  * @see PrivateKey
19  *
20  * @version 1.15 03/12/19
21  * @author Benjamin Renaud
22  */

23
24 public final class KeyPair implements java.io.Serializable JavaDoc {
25
26     private static final long serialVersionUID = -7565189502268009837L;
27
28     private PrivateKey JavaDoc privateKey;
29     private PublicKey JavaDoc publicKey;
30
31     /**
32      * Constructs a key pair from the given public key and private key.
33      *
34      * <p>Note that this constructor only stores references to the public
35      * and private key components in the generated key pair. This is safe,
36      * because <code>Key</code> objects are immutable.
37      *
38      * @param publicKey the public key.
39      *
40      * @param privateKey the private key.
41      */

42     public KeyPair(PublicKey JavaDoc publicKey, PrivateKey JavaDoc privateKey) {
43     this.publicKey = publicKey;
44     this.privateKey = privateKey;
45     }
46
47     /**
48      * Returns a reference to the public key component of this key pair.
49      *
50      * @return a reference to the public key.
51      */

52     public PublicKey JavaDoc getPublic() {
53     return publicKey;
54     }
55
56      /**
57      * Returns a reference to the private key component of this key pair.
58      *
59      * @return a reference to the private key.
60      */

61    public PrivateKey JavaDoc getPrivate() {
62     return privateKey;
63     }
64 }
65
Popular Tags