Package com.jcraft.jsch
Class KeyPair
- java.lang.Object
-
- com.jcraft.jsch.KeyPair
-
- Direct Known Subclasses:
KeyPairDSA
,KeyPairECDSA
,KeyPairPKCS8
,KeyPairRSA
public abstract class KeyPair extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
decrypt(byte[] _passphrase)
boolean
decrypt(String _passphrase)
void
dispose()
void
finalize()
abstract byte[]
forSSHAgent()
static KeyPair
genKeyPair(JSch jsch, int type)
static KeyPair
genKeyPair(JSch jsch, int type, int key_size)
String
getFingerPrint()
Returns the finger-print 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()
static KeyPair
load(JSch jsch, byte[] prvkey, byte[] pubkey)
static KeyPair
load(JSch jsch, String prvkey)
static KeyPair
load(JSch jsch, String prvfile, String pubfile)
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 http://www.ietf.org/rfc/rfc4716.txtvoid
writeSECSHPublicKey(String name, String comment)
Writes the public key with the specified comment to the output stream in the format defined in http://www.ietf.org/rfc/rfc4716.txt
-
-
-
Field Detail
-
ERROR
public static final int ERROR
- See Also:
- Constant Field Values
-
DSA
public static final int DSA
- See Also:
- Constant Field Values
-
RSA
public static final int RSA
- See Also:
- Constant Field Values
-
ECDSA
public static final int ECDSA
- See Also:
- Constant Field Values
-
UNKNOWN
public static final int UNKNOWN
- See Also:
- Constant Field Values
-
publicKeyComment
protected String publicKeyComment
-
encrypted
protected boolean encrypted
-
data
protected byte[] data
-
-
Constructor Detail
-
KeyPair
public KeyPair(JSch jsch)
-
-
Method Detail
-
genKeyPair
public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException
- Throws:
JSchException
-
genKeyPair
public static KeyPair genKeyPair(JSch jsch, int type, int key_size) throws JSchException
- Throws:
JSchException
-
getSignature
public abstract byte[] getSignature(byte[] data)
-
getVerifier
public abstract Signature getVerifier()
-
forSSHAgent
public abstract byte[] forSSHAgent() throws JSchException
- Throws:
JSchException
-
getPublicKeyComment
public String getPublicKeyComment()
-
setPublicKeyComment
public void setPublicKeyComment(String publicKeyComment)
-
writePrivateKey
public void writePrivateKey(OutputStream out)
Writes the plain private key to the given output stream.- Parameters:
out
- output stream- See Also:
writePrivateKey(java.io.OutputStream out, byte[] passphrase)
-
writePrivateKey
public void writePrivateKey(OutputStream out, byte[] passphrase)
Writes the cyphered private key to the given output stream.- Parameters:
out
- output streampassphrase
- a passphrase to encrypt the private key
-
getKeyType
public abstract int getKeyType()
-
getPublicKeyBlob
public byte[] getPublicKeyBlob()
Returns the blob of the public key.- Returns:
- blob of the public key
-
writePublicKey
public void writePublicKey(OutputStream out, String comment)
Writes the public key with the specified comment to the output stream.- Parameters:
out
- output streamcomment
- comment
-
writePublicKey
public void writePublicKey(String name, String comment) throws FileNotFoundException, IOException
Writes the public key with the specified comment to the file.- Parameters:
name
- file namecomment
- comment- Throws:
FileNotFoundException
IOException
- See Also:
writePublicKey(java.io.OutputStream out, String comment)
-
writeSECSHPublicKey
public void writeSECSHPublicKey(OutputStream out, String comment)
Writes the public key with the specified comment to the output stream in the format defined in http://www.ietf.org/rfc/rfc4716.txt- Parameters:
out
- output streamcomment
- comment
-
writeSECSHPublicKey
public void writeSECSHPublicKey(String name, String comment) throws FileNotFoundException, IOException
Writes the public key with the specified comment to the output stream in the format defined in http://www.ietf.org/rfc/rfc4716.txt- Parameters:
name
- file namecomment
- comment- Throws:
FileNotFoundException
IOException
- See Also:
writeSECSHPublicKey(java.io.OutputStream out, String comment)
-
writePrivateKey
public void writePrivateKey(String name) throws FileNotFoundException, IOException
Writes the plain private key to the file.- Parameters:
name
- file name- Throws:
FileNotFoundException
IOException
- See Also:
writePrivateKey(String name, byte[] passphrase)
-
writePrivateKey
public void writePrivateKey(String name, byte[] passphrase) throws FileNotFoundException, IOException
Writes the cyphered private key to the file.- Parameters:
name
- file namepassphrase
- a passphrase to encrypt the private key- Throws:
FileNotFoundException
IOException
- See Also:
writePrivateKey(java.io.OutputStream out, byte[] passphrase)
-
getFingerPrint
public String getFingerPrint()
Returns the finger-print of the public key.- Returns:
- finger print
-
setPassphrase
public void setPassphrase(String passphrase)
Deprecated.use #writePrivateKey(java.io.OutputStream out, byte[] passphrase)
-
setPassphrase
public void setPassphrase(byte[] passphrase)
Deprecated.use #writePrivateKey(String name, byte[] passphrase)
-
isEncrypted
public boolean isEncrypted()
-
decrypt
public boolean decrypt(String _passphrase)
-
decrypt
public boolean decrypt(byte[] _passphrase)
-
load
public static KeyPair load(JSch jsch, String prvkey) throws JSchException
- Throws:
JSchException
-
load
public static KeyPair load(JSch jsch, String prvfile, String pubfile) throws JSchException
- Throws:
JSchException
-
load
public static KeyPair load(JSch jsch, byte[] prvkey, byte[] pubkey) throws JSchException
- Throws:
JSchException
-
dispose
public void dispose()
-
-