001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.transport.publickey;
027:
028: /**
029: *
030: *
031: * @author $author$
032: * @version $Revision: 1.17 $
033: */
034: public abstract class SshKeyPair {
035: private SshPrivateKey prv;
036: private SshPublicKey pub;
037:
038: /**
039: * Creates a new SshKeyPair object.
040: */
041: public SshKeyPair() {
042: }
043:
044: /**
045: *
046: *
047: * @param bits
048: */
049: public abstract void generate(int bits);
050:
051: /**
052: *
053: *
054: * @param key
055: */
056: public void setPrivateKey(SshPrivateKey key) {
057: this .prv = key;
058: this .pub = key.getPublicKey();
059: }
060:
061: /**
062: *
063: *
064: * @param encoded
065: *
066: * @return
067: *
068: * @throws InvalidSshKeyException
069: */
070: public SshPrivateKey setPrivateKey(byte[] encoded)
071: throws InvalidSshKeyException {
072: setPrivateKey(decodePrivateKey(encoded));
073:
074: return this .prv;
075: }
076:
077: /**
078: *
079: *
080: * @return
081: */
082: public SshPrivateKey getPrivateKey() {
083: return prv;
084: }
085:
086: /**
087: *
088: *
089: * @param encoded
090: *
091: * @return
092: *
093: * @throws InvalidSshKeyException
094: */
095: public SshPublicKey setPublicKey(byte[] encoded)
096: throws InvalidSshKeyException {
097: this .pub = decodePublicKey(encoded);
098: this .prv = null;
099:
100: return this .pub;
101: }
102:
103: /**
104: *
105: *
106: * @return
107: */
108: public SshPublicKey getPublicKey() {
109: return pub;
110: }
111:
112: /**
113: *
114: *
115: * @param encoded
116: *
117: * @return
118: *
119: * @throws InvalidSshKeyException
120: */
121: public abstract SshPrivateKey decodePrivateKey(byte[] encoded)
122: throws InvalidSshKeyException;
123:
124: /**
125: *
126: *
127: * @param encoded
128: *
129: * @return
130: *
131: * @throws InvalidSshKeyException
132: */
133: public abstract SshPublicKey decodePublicKey(byte[] encoded)
134: throws InvalidSshKeyException;
135: }
|