examples
Class GenerateKeyPair
java.lang.Object
examples.GenerateKeyPair
public class GenerateKeyPair
- extends java.lang.Object
This is a simple demo of how to generate public key pairs for use with ssh2.
A file containing some definitions of the key must supplied as argument.
Usage:
java -cp examples.jar examples.GenerateKeyPair
definition_file
The definition file is a standard Java property file which should
contain the following properties:
- format
- Format of keyfile. Valid values are
openssh
and
sshinc
. The default value is openssh.
- algorithm
- Which algorithm to generate a key for. Valid valus are
RSA
and DSA
. The default value is RSA.
- bits
- Number of bits in key. The default value is 1024.
- password
- Password used to encrypt the private key
- subject
- String identifying the owner of the key
- comment
- Key comment
- keyfile
- Base-name of files to save keys in. The private file will be
stored in keyfile and the public key in
keyfile
.pub
Method Summary |
static KeyPair |
generateKeyPair(java.lang.String alg,
int bits,
SecureRandom rand)
Actually generate the key pair |
static void |
main(java.lang.String[] argv)
Run the application |
static void |
saveKeyPair(KeyPair kp,
java.lang.String passwd,
java.lang.String fileName,
java.lang.String subject,
java.lang.String comment,
boolean sshComFormat,
SecureRandom rand)
Save the given keypair to a file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GenerateKeyPair
public GenerateKeyPair()
generateKeyPair
public static KeyPair generateKeyPair(java.lang.String alg,
int bits,
SecureRandom rand)
throws NoSuchAlgorithmException
- Actually generate the key pair
- Parameters:
alg
- algorithm to generate for (RSA or DSA)bits
- key sizerand
- random number source
- Throws:
NoSuchAlgorithmException
saveKeyPair
public static void saveKeyPair(KeyPair kp,
java.lang.String passwd,
java.lang.String fileName,
java.lang.String subject,
java.lang.String comment,
boolean sshComFormat,
SecureRandom rand)
throws java.io.IOException,
SSH2Exception,
NoSuchAlgorithmException
- Save the given keypair to a file.
- Throws:
java.io.IOException
SSH2Exception
NoSuchAlgorithmException
main
public static void main(java.lang.String[] argv)
- Run the application