KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > pki > SshKeyPair


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
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 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security.pki;
21
22 /**
23  *
24  *
25  * @author $author$
26  */

27 public abstract class SshKeyPair {
28     private SshPrivateKey prv;
29     private SshPublicKey pub;
30
31     /**
32      * Creates a new SshKeyPair object.
33      */

34     public SshKeyPair() {
35     }
36
37     /**
38      *
39      *
40      * @param bits
41      */

42     public abstract void generate(int bits);
43
44     /**
45      *
46      *
47      * @param key
48      */

49     public void setPrivateKey(SshPrivateKey key) {
50         this.prv = key;
51         this.pub = key.getPublicKey();
52     }
53
54     /**
55      *
56      *
57      * @param encoded
58      *
59      * @return SshPrivateKey
60      *
61      * @throws InvalidKeyException
62      */

63     public SshPrivateKey setPrivateKey(byte[] encoded)
64         throws InvalidKeyException {
65         setPrivateKey(decodePrivateKey(encoded));
66
67         return this.prv;
68     }
69
70     /**
71      *
72      *
73      * @return
74      */

75     public SshPrivateKey getPrivateKey() {
76         return prv;
77     }
78
79     /**
80      *
81      *
82      * @param encoded
83      *
84      * @return SshPublicKey
85      *
86      * @throws InvalidKeyException
87      */

88     public SshPublicKey setPublicKey(byte[] encoded)
89         throws InvalidKeyException {
90         this.pub = decodePublicKey(encoded);
91         this.prv = null;
92
93         return this.pub;
94     }
95
96     /**
97      *
98      *
99      * @return SshPublicKey
100      */

101     public SshPublicKey getPublicKey() {
102         return pub;
103     }
104
105     /**
106      *
107      *
108      * @param encoded
109      *
110      * @return SshPrivateKey
111      *
112      * @throws InvalidKeyException
113      */

114     public abstract SshPrivateKey decodePrivateKey(byte[] encoded)
115         throws InvalidKeyException;
116
117     /**
118      *
119      *
120      * @param encoded
121      *
122      * @return SshPublicKey
123      *
124      * @throws InvalidKeyException
125      */

126     public abstract SshPublicKey decodePublicKey(byte[] encoded)
127         throws InvalidKeyException;
128 }
129
Popular Tags