Class SshKeyPairGenerator

java.lang.Object
com.sshtools.common.publickey.SshKeyPairGenerator

public class SshKeyPairGenerator extends Object

Generate public/private key pairs.

To generate a new pair use the following code

 SshKeyPair pair = SshKeyPairGenerator.generateKeyPair(SshKeyPairGenerator.SSH2_RSA, 1024);
 
To create formatted key file for the public key use:
 SshPublicKeyFile pubfile = SshPublicKeyFileFactory.create(pair.getPublicKey(), "Some comment",
                SshPublicKeyFileFactory.OPENSSH_FORMAT);
 FileOutputStream fout = new FileOutputStream("mykey.pub");
 fout.write(pubfile.getFormattedKey());
 fout.close();
 
To create a formatted, encrypted private key file use:
 SshPrivateKeyFile prvfile = SshPrivateKeyFileFactory.create(pair, "my passphrase", "Some comment",
                SshPrivateKeyFileFactory.OPENSSH_FORMAT);
 FileOutputStream fout = new FileOutputStream("mykey");
 fout.write(prvfile.getFormattedKey());
 fout.close();
 

Author:
Lee David Painter