View Javadoc

1   /********************************************************************************
2    *InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  package base.jdbs.cryptography.asymmetric;
21  
22  import java.security.cert.X509Certificate;
23  
24  import org.apache.log4j.Logger;
25  
26  public class KeyPair {
27  
28  	private static final transient Logger logger = Logger.getLogger(KeyPair.class.getName());
29  
30  	/***The keypairs' identifier.**/
31  	private final Integer id;
32  	/***The asymmetric public key associated to the keypair.**/
33  	private final PublicKey publicKey;
34  	/***The asymmetric private key associated to the keypair.**/
35  	private final PrivateKey privateKey;
36  	/***The keypairs' certificate**/
37  	private final X509Certificate certificate;
38  	/***The keypairs' name.**/
39  	private final String name;
40  	
41  	/***
42  	 * @param id The unique keypair's identifier.
43  	 * @param name The keypairs' name.
44  	 * @param publicKey The keypairs'public key.
45  	 * @param privateKey The keypairs' private key.
46  	 * @param certificate The keypairs' certificate.
47  	 */
48  	public KeyPair(Integer id, String name, PublicKey publicKey, PrivateKey privateKey, X509Certificate certificate) {
49  		this.id = id;
50  		this.name = name;
51  		this.publicKey = publicKey;
52  		this.privateKey = privateKey;
53  		this.certificate = certificate;
54  	}
55  	
56  	/***
57  	 * @return Returns the id.
58  	 */
59  	public Integer getId() {
60  		return id;
61  	}
62  
63  	/***
64  	 * @return Returns the privateKey.
65  	 */
66  	public PrivateKey getPrivateKey() {
67  		return privateKey;
68  	}
69  
70  	/***
71  	 * @return Returns the publicKey.
72  	 */
73  	public PublicKey getPublicKey() {
74  		return publicKey;
75  	}
76  
77  	/***
78  	 * @return Returns the name.
79  	 */
80  	public String getName() {
81  		return name;
82  	}
83  	
84  	/***
85  	 * This method builds an alias for the keypair instance.
86  	 * @return The alias associated to the keypair instance.
87  	 */
88  	public String alias(){
89  		return this.id + " " + this.name;
90  	}
91  
92  	/***
93  	 * @return Returns the certificate.
94  	 */
95  	public X509Certificate getCertificate() {
96  		return certificate;
97  	}
98  }