public abstract class KeyPair extends Object
An application may use this class to generate new
keys with genKeyPair
, and
then write the KeyPair to files, which then might
be used with JSch.addIdentity
.
Another possible use would be to load a key pair in order to change the passphrase.
Modifier and Type | Field and Description |
---|---|
protected byte[] |
data |
static int |
DSA
Key type constant: DSA.
|
static int |
ECDSA |
protected boolean |
encrypted |
static int |
ERROR
Key type constant: some error occured,
or the keypair was not initialized.
|
protected String |
publicKeyComment |
static int |
RSA
Key type constant: RSA.
|
static int |
UNKNOWN
Key type constant: unknown key type.
|
Constructor and Description |
---|
KeyPair(JSch jsch)
Creates a new KeyPair.
|
Modifier and Type | Method and Description |
---|---|
boolean |
decrypt(byte[] _passphrase)
decrypts the private key, using a passphrase.
|
boolean |
decrypt(String _passphrase)
decrypts the private key, using a passphrase.
|
void |
dispose()
Disposes this key pair.
|
void |
finalize()
Called by the garbage collector when the object is not reachable anymore.
|
abstract byte[] |
forSSHAgent() |
static KeyPair |
genKeyPair(JSch jsch,
int type)
Creates a new key pair with default key size of 1024 bits.
|
static KeyPair |
genKeyPair(JSch jsch,
int type,
int key_size)
Creates a new key pair.
|
String |
getFingerPrint()
Creates and returns a fingerprint of the public key,
i.e. the hexadecimal representation of the MD5 hash of
the public key.
|
abstract int |
getKeyType()
|
byte[] |
getPublicKeyBlob()
Returns the blob of the public key.
|
String |
getPublicKeyComment() |
abstract byte[] |
getSignature(byte[] data) |
abstract Signature |
getVerifier() |
boolean |
isEncrypted()
checks whether the private key currently is encrypted.
|
static KeyPair |
load(JSch jsch,
byte[] prvkey,
byte[] pubkey) |
static KeyPair |
load(JSch jsch,
String prvkey)
Loads a key pair from a pair of files.
|
static KeyPair |
load(JSch jsch,
String prvfile,
String pubfile)
Loads a key pair from a pair of files.
|
void |
setPassphrase(byte[] passphrase)
Deprecated.
use #writePrivateKey(String name, byte[] passphrase)
|
void |
setPassphrase(String passphrase)
Deprecated.
use #writePrivateKey(java.io.OutputStream out, byte[] passphrase)
|
void |
setPublicKeyComment(String publicKeyComment) |
void |
writePrivateKey(OutputStream out)
Writes the plain private key to the given output stream.
|
void |
writePrivateKey(OutputStream out,
byte[] passphrase)
Writes the cyphered private key to the given output stream.
|
void |
writePrivateKey(String name)
Writes the plain private key to the file.
|
void |
writePrivateKey(String name,
byte[] passphrase)
Writes the cyphered private key to the file.
|
void |
writePublicKey(OutputStream out,
String comment)
Writes the public key with the specified comment to the output stream.
|
void |
writePublicKey(String name,
String comment)
Writes the public key with the specified comment to the file.
|
void |
writeSECSHPublicKey(OutputStream out,
String comment)
Writes the public key with the specified comment to the output stream in
the format defined in RFC 4716,
The Secure Shell (SSH) Public Key File Format.
|
void |
writeSECSHPublicKey(String name,
String comment)
Writes the public key with the specified comment to the output stream in
the format defined in RFC 4716,
The Secure Shell (SSH) Public Key File Format
|
public static final int ERROR
public static final int DSA
public static final int RSA
public static final int ECDSA
public static final int UNKNOWN
protected String publicKeyComment
protected boolean encrypted
protected byte[] data
public KeyPair(JSch jsch)
As this class is abstract, this constructor can actually only be
called by subclasses, and should be protected
instead of
public. Actually, a default-access constructor would be enough,
since this class already contains some abstract default-access methods
and as such cannot be implemented outside the package.
public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException
jsch
- the JSch object used for configuration purposes.type
- one of DSA
and RSA
.JSchException
public static KeyPair genKeyPair(JSch jsch, int type, int key_size) throws JSchException
jsch
- the JSch object used for configuration purposes.type
- one of DSA
and RSA
.key_size
- the size of the keys, in bits.JSchException
public abstract byte[] getSignature(byte[] data)
public abstract Signature getVerifier()
public abstract byte[] forSSHAgent() throws JSchException
JSchException
public String getPublicKeyComment()
public void setPublicKeyComment(String publicKeyComment)
public void writePrivateKey(OutputStream out)
out
- output streamwritePrivateKey(java.io.OutputStream out, byte[] passphrase)
public void writePrivateKey(OutputStream out, byte[] passphrase)
out
- output streampassphrase
- a passphrase to encrypt the private keypublic abstract int getKeyType()
public byte[] getPublicKeyBlob()
public void writePublicKey(OutputStream out, String comment)
out
- output streamcomment
- commentpublic void writePublicKey(String name, String comment) throws FileNotFoundException, IOException
name
- file namecomment
- commentFileNotFoundException
IOException
writePublicKey(java.io.OutputStream out, String comment)
public void writeSECSHPublicKey(OutputStream out, String comment)
out
- output streamcomment
- commentpublic void writeSECSHPublicKey(String name, String comment) throws FileNotFoundException, IOException
name
- file namecomment
- commentFileNotFoundException
IOException
writeSECSHPublicKey(java.io.OutputStream out, String comment)
public void writePrivateKey(String name) throws FileNotFoundException, IOException
name
- file nameFileNotFoundException
IOException
writePrivateKey(String name, byte[] passphrase)
public void writePrivateKey(String name, byte[] passphrase) throws FileNotFoundException, IOException
name
- file namepassphrase
- a passphrase to encrypt the private keyFileNotFoundException
IOException
writePrivateKey(java.io.OutputStream out, byte[] passphrase)
public String getFingerPrint()
public void setPassphrase(String passphrase)
public void setPassphrase(byte[] passphrase)
public boolean isEncrypted()
public boolean decrypt(String _passphrase)
public boolean decrypt(byte[] _passphrase)
public static KeyPair load(JSch jsch, String prvkey) throws JSchException
jsch
- the JSch object used to obtain configuration.prvkey
- the file name of the private key file.
The public key is expected in a file with same name and suffix
.pub
.JSchException
public static KeyPair load(JSch jsch, String prvfile, String pubfile) throws JSchException
jsch
- the JSch object used to obtain configuration.prvfile
- the file name of the private key file.pubfile
- the file name of the public key file.JSchException
public static KeyPair load(JSch jsch, byte[] prvkey, byte[] pubkey) throws JSchException
JSchException
public void dispose()
This is an inofficial Javadoc created by PaĆlo Ebermann. Have a look at the official homepage.