com.mindbright.ssh2
public class SSH2KeyPairFile extends java.lang.Object
SSH2PublicKeyFile
Modifier and Type | Class and Description |
---|---|
static class |
SSH2KeyPairFile.PEMDSAPrivate
Handles PEM encoding of a DSA key.
|
static class |
SSH2KeyPairFile.PEMECPrivate |
static class |
SSH2KeyPairFile.PEMRSAPrivate |
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
BEGIN_PRV_KEY |
static java.lang.String[] |
END_PRV_KEY |
static java.lang.String |
FILE_COMMENT |
static java.lang.String |
FILE_SUBJECT |
static java.lang.String |
PRV_DEKINFO |
static java.lang.String |
PRV_PROCTYPE |
static int |
SSH_PRIVATE_KEY_MAGIC |
Constructor and Description |
---|
SSH2KeyPairFile()
This is the constructor used for loading a key pair.
|
SSH2KeyPairFile(java.security.KeyPair keyPair,
java.lang.String subject,
java.lang.String comment)
This is the constructor used for storing a key pair.
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
expandPasswordToKey(java.lang.String password,
int keyLen,
byte[] salt) |
static byte[] |
expandPasswordToKeySSHCom(java.lang.String password,
int keyLen) |
java.lang.String |
getAlgorithmName() |
ASCIIArmour |
getArmour() |
int |
getBitLength() |
java.lang.String |
getComment() |
java.security.KeyPair |
getKeyPair()
Extract the key pair.
|
java.lang.String |
getSubject() |
boolean |
isPuttyFormat() |
boolean |
isSSHComFormat() |
void |
load(java.io.InputStream in,
java.lang.String password)
Load key pair from stream.
|
void |
load(java.lang.String fileName,
java.lang.String password)
Load key pair from file.
|
static java.security.KeyPair |
readKeyPair(ASCIIArmour armour,
byte[] keyBlob,
java.lang.String password) |
static java.security.KeyPair |
readKeyPairSSHCom(byte[] keyBlob,
java.lang.String password) |
void |
setComment(java.lang.String comment) |
void |
setSubject(java.lang.String subject) |
void |
store(java.io.OutputStream out,
java.security.SecureRandom random,
java.lang.String password,
boolean sshComFormat)
Store the key pair in the given stream with more format control
|
void |
store(java.lang.String fileName,
java.security.SecureRandom random,
java.lang.String password)
Store the key pair in the given file
|
void |
store(java.lang.String fileName,
java.security.SecureRandom random,
java.lang.String password,
boolean sshComFormat)
Store the key pair in the given file with more format control
|
static byte[] |
writeKeyPair(ASCIIArmour armour,
java.lang.String password,
java.security.SecureRandom random,
java.security.KeyPair keyPair) |
static byte[] |
writeKeyPairSSHCom(java.lang.String password,
java.lang.String cipher,
java.security.KeyPair keyPair) |
public static final java.lang.String[] BEGIN_PRV_KEY
public static final java.lang.String[] END_PRV_KEY
public static final int SSH_PRIVATE_KEY_MAGIC
public static final java.lang.String PRV_PROCTYPE
public static final java.lang.String PRV_DEKINFO
public static final java.lang.String FILE_SUBJECT
public static final java.lang.String FILE_COMMENT
public SSH2KeyPairFile(java.security.KeyPair keyPair, java.lang.String subject, java.lang.String comment)
keyPair
- the key pair to storesubject
- the subject name of the key ownercomment
- a comment to accompany the keypublic SSH2KeyPairFile()
public java.security.KeyPair getKeyPair()
public java.lang.String getSubject()
public void setSubject(java.lang.String subject)
public java.lang.String getComment()
public void setComment(java.lang.String comment)
public ASCIIArmour getArmour()
public boolean isSSHComFormat()
public boolean isPuttyFormat()
public java.lang.String getAlgorithmName()
public int getBitLength()
public static byte[] writeKeyPair(ASCIIArmour armour, java.lang.String password, java.security.SecureRandom random, java.security.KeyPair keyPair) throws SSH2FatalException
SSH2FatalException
public static byte[] writeKeyPairSSHCom(java.lang.String password, java.lang.String cipher, java.security.KeyPair keyPair) throws SSH2FatalException
SSH2FatalException
public static java.security.KeyPair readKeyPair(ASCIIArmour armour, byte[] keyBlob, java.lang.String password) throws SSH2Exception
SSH2Exception
public static java.security.KeyPair readKeyPairSSHCom(byte[] keyBlob, java.lang.String password) throws SSH2Exception
SSH2Exception
public void store(java.lang.String fileName, java.security.SecureRandom random, java.lang.String password) throws java.io.IOException, SSH2FatalException
fileName
- name of file to store keys inrandom
- random number generator used when encrypting the
keyspassword
- password to use when encrypting the keysjava.io.IOException
SSH2FatalException
public void store(java.lang.String fileName, java.security.SecureRandom random, java.lang.String password, boolean sshComFormat) throws java.io.IOException, SSH2FatalException
fileName
- name of file to store keys inrandom
- random number generator used when encrypting the
keyspassword
- password to use when encrypting the keyssshComFormat
- if tru store the key in the ssh.com formatjava.io.IOException
SSH2FatalException
public void store(java.io.OutputStream out, java.security.SecureRandom random, java.lang.String password, boolean sshComFormat) throws java.io.IOException, SSH2FatalException
out
- output stream to store keys to. Note that this
stream will not be closed.random
- random number generator used when encrypting the
keyspassword
- password to use when encrypting the keyssshComFormat
- if tru store the key in the ssh.com formatjava.io.IOException
SSH2FatalException
public void load(java.lang.String fileName, java.lang.String password) throws java.io.IOException, SSH2Exception
fileName
- name of file to load keys frompassword
- password used to encrypt the filejava.io.IOException
SSH2Exception
public void load(java.io.InputStream in, java.lang.String password) throws java.io.IOException, SSH2Exception
in
- input stream from which the key pair is read. It will
be wrapped in a PushbackInputStream, but not closed.password
- password used to encrypt the filejava.io.IOException
SSH2Exception
public static byte[] expandPasswordToKey(java.lang.String password, int keyLen, byte[] salt)
public static byte[] expandPasswordToKeySSHCom(java.lang.String password, int keyLen)