|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindbright.ssh2.SSH2KeyPairFile
public class SSH2KeyPairFile
This class implements the file formats commonly used for storing key pairs for public key authentication. It can handle both OpenSSH's PEM file format as well as SSH Communications proprietary format for DSA keys. It can also read the PuTTY key file format. When importing/exporting use the appropriate constructor and the load/store methods. Note that this class can also be used to convert key pair files between the formats.
SSH2PublicKeyFile
Nested Class Summary | |
---|---|
static class |
SSH2KeyPairFile.PEMDSAPrivate
Handles PEM encoding of a DSA key. |
Field Summary | |
---|---|
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 Summary | |
---|---|
SSH2KeyPairFile()
This is the constructor used for loading a key pair. |
|
SSH2KeyPairFile(KeyPair keyPair,
java.lang.String subject,
java.lang.String comment)
This is the constructor used for storing a key pair. |
Method Summary | |
---|---|
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()
|
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 KeyPair |
readKeyPair(ASCIIArmour armour,
byte[] keyBlob,
java.lang.String password)
|
static 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,
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,
SecureRandom random,
java.lang.String password)
Store the key pair in the given file |
void |
store(java.lang.String fileName,
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,
SecureRandom random,
KeyPair keyPair)
|
static byte[] |
writeKeyPairSSHCom(java.lang.String password,
java.lang.String cipher,
KeyPair keyPair)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
public SSH2KeyPairFile(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()
Method Detail |
---|
public 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, SecureRandom random, KeyPair keyPair) throws SSH2FatalException
SSH2FatalException
public static byte[] writeKeyPairSSHCom(java.lang.String password, java.lang.String cipher, KeyPair keyPair) throws SSH2FatalException
SSH2FatalException
public static KeyPair readKeyPair(ASCIIArmour armour, byte[] keyBlob, java.lang.String password) throws SSH2Exception
SSH2Exception
public static KeyPair readKeyPairSSHCom(byte[] keyBlob, java.lang.String password) throws SSH2Exception
SSH2Exception
public void store(java.lang.String fileName, 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 keys
java.io.IOException
SSH2FatalException
public void store(java.lang.String fileName, 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 format
java.io.IOException
SSH2FatalException
public void store(java.io.OutputStream out, 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 format
java.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 file
java.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 file
java.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)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |