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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
KeyPair.ASN1
(package private) class
KeyPair.ASN1Exception
-
Field Summary
Fields Modifier and Type Field Description private Cipher
cipher
private static byte[]
cr
protected byte[]
data
static int
DSA
static int
ECDSA
protected boolean
encrypted
static int
ERROR
private HASH
hash
(package private) static byte[][]
header
private static java.lang.String[]
header1
private static java.lang.String[]
header2
private static java.lang.String[]
header3
private byte[]
iv
(package private) JSch
jsch
private byte[]
passphrase
private byte[]
publickeyblob
protected java.lang.String
publicKeyComment
private Random
random
static int
RSA
private static byte[]
space
static int
UNKNOWN
(package private) int
vendor
(package private) static int
VENDOR_FSECURE
(package private) static int
VENDOR_OPENSSH
(package private) static int
VENDOR_PKCS8
(package private) static int
VENDOR_PUTTY
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static byte
a2b(byte c)
private static byte
b2a(byte c)
(package private) void
copy(KeyPair kpair)
(package private) int
countLength(int len)
boolean
decrypt(byte[] _passphrase)
private byte[]
decrypt(byte[] data, byte[] passphrase, byte[] iv)
boolean
decrypt(java.lang.String _passphrase)
void
dispose()
private byte[]
encrypt(byte[] plain, byte[][] _iv, byte[] passphrase)
void
finalize()
abstract byte[]
forSSHAgent()
private Cipher
genCipher()
(package private) abstract void
generate(int key_size)
private HASH
genHash()
(package private) byte[]
genKey(byte[] passphrase, byte[] iv)
static KeyPair
genKeyPair(JSch jsch, int type)
static KeyPair
genKeyPair(JSch jsch, int type, int key_size)
private Random
genRandom()
(package private) abstract byte[]
getBegin()
(package private) abstract byte[]
getEnd()
java.lang.String
getFingerPrint()
Returns the finger-print of the public key.(package private) abstract int
getKeySize()
abstract int
getKeyType()
(package private) abstract byte[]
getKeyTypeName()
(package private) abstract byte[]
getPrivateKey()
byte[]
getPublicKeyBlob()
Returns the blob of the public key.java.lang.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, java.lang.String prvkey)
static KeyPair
load(JSch jsch, java.lang.String prvfile, java.lang.String pubfile)
(package private) static KeyPair
loadPPK(JSch jsch, byte[] buf)
(package private) abstract boolean
parse(byte[] data)
private static boolean
parseHeader(Buffer buffer, java.util.Hashtable v)
private static byte[]
parseLines(Buffer buffer, int lines)
void
setPassphrase(byte[] passphrase)
Deprecated.use #writePrivateKey(String name, byte[] passphrase)void
setPassphrase(java.lang.String passphrase)
Deprecated.use #writePrivateKey(java.io.OutputStream out, byte[] passphrase)void
setPublicKeyComment(java.lang.String publicKeyComment)
(package private) int
writeDATA(byte[] buf, byte n, int index, byte[] data)
(package private) int
writeINTEGER(byte[] buf, int index, byte[] data)
(package private) int
writeLength(byte[] data, int index, int len)
(package private) int
writeOCTETSTRING(byte[] buf, int index, byte[] data)
void
writePrivateKey(java.io.OutputStream out)
Writes the plain private key to the given output stream.void
writePrivateKey(java.io.OutputStream out, byte[] passphrase)
Writes the cyphered private key to the given output stream.void
writePrivateKey(java.lang.String name)
Writes the plain private key to the file.void
writePrivateKey(java.lang.String name, byte[] passphrase)
Writes the cyphered private key to the file.void
writePublicKey(java.io.OutputStream out, java.lang.String comment)
Writes the public key with the specified comment to the output stream.void
writePublicKey(java.lang.String name, java.lang.String comment)
Writes the public key with the specified comment to the file.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.txtvoid
writeSECSHPublicKey(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(package private) int
writeSEQUENCE(byte[] buf, int index, int len)
-
-
-
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
-
VENDOR_OPENSSH
static final int VENDOR_OPENSSH
- See Also:
- Constant Field Values
-
VENDOR_FSECURE
static final int VENDOR_FSECURE
- See Also:
- Constant Field Values
-
VENDOR_PUTTY
static final int VENDOR_PUTTY
- See Also:
- Constant Field Values
-
VENDOR_PKCS8
static final int VENDOR_PKCS8
- See Also:
- Constant Field Values
-
vendor
int vendor
-
cr
private static final byte[] cr
-
publicKeyComment
protected java.lang.String publicKeyComment
-
jsch
JSch jsch
-
cipher
private Cipher cipher
-
hash
private HASH hash
-
random
private Random random
-
passphrase
private byte[] passphrase
-
header
static byte[][] header
-
space
private static byte[] space
-
encrypted
protected boolean encrypted
-
data
protected byte[] data
-
iv
private byte[] iv
-
publickeyblob
private byte[] publickeyblob
-
header1
private static final java.lang.String[] header1
-
header2
private static final java.lang.String[] header2
-
header3
private static final java.lang.String[] header3
-
-
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
-
generate
abstract void generate(int key_size) throws JSchException
- Throws:
JSchException
-
getBegin
abstract byte[] getBegin()
-
getEnd
abstract byte[] getEnd()
-
getKeySize
abstract int getKeySize()
-
getSignature
public abstract byte[] getSignature(byte[] data)
-
getVerifier
public abstract Signature getVerifier()
-
forSSHAgent
public abstract byte[] forSSHAgent() throws JSchException
- Throws:
JSchException
-
getPublicKeyComment
public java.lang.String getPublicKeyComment()
-
setPublicKeyComment
public void setPublicKeyComment(java.lang.String publicKeyComment)
-
getPrivateKey
abstract byte[] getPrivateKey()
-
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
-
getKeyTypeName
abstract byte[] getKeyTypeName()
-
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.IOException
Writes the public key with the specified comment to the file.- Parameters:
name
- file namecomment
- comment- Throws:
java.io.FileNotFoundException
java.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.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:
java.io.FileNotFoundException
java.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.IOException
Writes the plain private key to the file.- Parameters:
name
- file name- Throws:
java.io.FileNotFoundException
java.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.IOException
Writes the cyphered private key to the file.- Parameters:
name
- file namepassphrase
- a passphrase to encrypt the private key- Throws:
java.io.FileNotFoundException
java.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
-
encrypt
private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase)
-
parse
abstract boolean parse(byte[] data)
-
decrypt
private byte[] decrypt(byte[] data, byte[] passphrase, byte[] iv)
-
writeSEQUENCE
int writeSEQUENCE(byte[] buf, int index, int len)
-
writeINTEGER
int writeINTEGER(byte[] buf, int index, byte[] data)
-
writeOCTETSTRING
int writeOCTETSTRING(byte[] buf, int index, byte[] data)
-
writeDATA
int writeDATA(byte[] buf, byte n, int index, byte[] data)
-
countLength
int countLength(int len)
-
writeLength
int writeLength(byte[] data, int index, int len)
-
genRandom
private Random genRandom()
-
genHash
private HASH genHash()
-
genCipher
private Cipher genCipher()
-
genKey
byte[] genKey(byte[] passphrase, byte[] iv)
-
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
public static KeyPair load(JSch jsch, java.lang.String prvkey) throws JSchException
- Throws:
JSchException
-
load
public static KeyPair load(JSch jsch, java.lang.String prvfile, java.lang.String pubfile) throws JSchException
- Throws:
JSchException
-
load
public static KeyPair load(JSch jsch, byte[] prvkey, byte[] pubkey) throws JSchException
- Throws:
JSchException
-
a2b
private static byte a2b(byte c)
-
b2a
private static byte b2a(byte c)
-
dispose
public void dispose()
-
finalize
public void finalize()
- Overrides:
finalize
in classjava.lang.Object
-
loadPPK
static KeyPair loadPPK(JSch jsch, byte[] buf) throws JSchException
- Throws:
JSchException
-
parseLines
private static byte[] parseLines(Buffer buffer, int lines)
-
parseHeader
private static boolean parseHeader(Buffer buffer, java.util.Hashtable v)
-
copy
void copy(KeyPair kpair)
-
-