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 java.lang.Object
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description booleandecrypt(byte[] _passphrase)booleandecrypt(java.lang.String _passphrase)voiddispose()voidfinalize()abstract byte[]forSSHAgent()static KeyPairgenKeyPair(JSch jsch, int type)static KeyPairgenKeyPair(JSch jsch, int type, int key_size)java.lang.StringgetFingerPrint()Returns the finger-print of the public key.abstract intgetKeyType()byte[]getPublicKeyBlob()Returns the blob of the public key.java.lang.StringgetPublicKeyComment()abstract byte[]getSignature(byte[] data)abstract byte[]getSignature(byte[] data, java.lang.String alg)abstract SignaturegetVerifier()abstract SignaturegetVerifier(java.lang.String alg)booleanisEncrypted()static KeyPairload(JSch jsch, byte[] prvkey, byte[] pubkey)static KeyPairload(JSch jsch, java.lang.String prvkey)static KeyPairload(JSch jsch, java.lang.String prvfile, java.lang.String pubfile)voidsetPassphrase(byte[] passphrase)Deprecated.use #writePrivateKey(String name, byte[] passphrase)voidsetPassphrase(java.lang.String passphrase)Deprecated.use #writePrivateKey(java.io.OutputStream out, byte[] passphrase)voidsetPublicKeyComment(java.lang.String publicKeyComment)voidwritePrivateKey(java.io.OutputStream out)Writes the plain private key to the given output stream.voidwritePrivateKey(java.io.OutputStream out, byte[] passphrase)Writes the cyphered private key to the given output stream.voidwritePrivateKey(java.lang.String name)Writes the plain private key to the file.voidwritePrivateKey(java.lang.String name, byte[] passphrase)Writes the cyphered private key to the file.voidwritePublicKey(java.io.OutputStream out, java.lang.String comment)Writes the public key with the specified comment to the output stream.voidwritePublicKey(java.lang.String name, java.lang.String comment)Writes the public key with the specified comment to the file.voidwriteSECSHPublicKey(java.io.OutputStream out, java.lang.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.txtvoidwriteSECSHPublicKey(java.lang.String name, java.lang.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 Details
-
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 java.lang.String publicKeyComment -
encrypted
protected boolean encrypted -
data
protected byte[] data
-
-
Constructor Details
-
Method Details
-
genKeyPair
- Throws:
JSchException
-
genKeyPair
- Throws:
JSchException
-
getSignature
public abstract byte[] getSignature(byte[] data) -
getSignature
public abstract byte[] getSignature(byte[] data, java.lang.String alg) -
getVerifier
-
getVerifier
-
forSSHAgent
- Throws:
JSchException
-
getPublicKeyComment
public java.lang.String getPublicKeyComment() -
setPublicKeyComment
public void setPublicKeyComment(java.lang.String publicKeyComment) -
writePrivateKey
public void writePrivateKey(java.io.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(java.io.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(java.io.OutputStream out, java.lang.String comment)Writes the public key with the specified comment to the output stream.- Parameters:
out- output streamcomment- comment
-
writePublicKey
public void writePublicKey(java.lang.String name, java.lang.String comment) throws java.io.FileNotFoundException, java.io.IOExceptionWrites the public key with the specified comment to the file.- Parameters:
name- file namecomment- comment- Throws:
java.io.FileNotFoundExceptionjava.io.IOException- See Also:
writePublicKey(java.io.OutputStream out, String comment)
-
writeSECSHPublicKey
public void writeSECSHPublicKey(java.io.OutputStream out, java.lang.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(java.lang.String name, java.lang.String comment) throws java.io.FileNotFoundException, java.io.IOExceptionWrites 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:
java.io.FileNotFoundExceptionjava.io.IOException- See Also:
writeSECSHPublicKey(java.io.OutputStream out, String comment)
-
writePrivateKey
public void writePrivateKey(java.lang.String name) throws java.io.FileNotFoundException, java.io.IOExceptionWrites the plain private key to the file.- Parameters:
name- file name- Throws:
java.io.FileNotFoundExceptionjava.io.IOException- See Also:
writePrivateKey(String name, byte[] passphrase)
-
writePrivateKey
public void writePrivateKey(java.lang.String name, byte[] passphrase) throws java.io.FileNotFoundException, java.io.IOExceptionWrites the cyphered private key to the file.- Parameters:
name- file namepassphrase- a passphrase to encrypt the private key- Throws:
java.io.FileNotFoundExceptionjava.io.IOException- See Also:
writePrivateKey(java.io.OutputStream out, byte[] passphrase)
-
getFingerPrint
public java.lang.String getFingerPrint()Returns the finger-print of the public key.- Returns:
- finger print
-
setPassphrase
public void setPassphrase(java.lang.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(java.lang.String _passphrase) -
decrypt
public boolean decrypt(byte[] _passphrase) -
load
- Throws:
JSchException
-
load
public static KeyPair load(JSch jsch, java.lang.String prvfile, java.lang.String pubfile) throws JSchException- Throws:
JSchException
-
load
- Throws:
JSchException
-
dispose
public void dispose() -
finalize
public void finalize()- Overrides:
finalizein classjava.lang.Object
-