Package com.sshtools.common.publickey
Class SshKeyPairGenerator
java.lang.Object
com.sshtools.common.publickey.SshKeyPairGenerator
Generate public/private key pairs.
To generate a new pair use the following code
To create formatted key file for the public key use:SshKeyPair pair = SshKeyPairGenerator.generateKeyPair(SshKeyPairGenerator.SSH2_RSA, 1024);
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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SshKeyPairgenerateKeyPair(String algorithm) Generate a new key pair using the default bit size.static SshKeyPairgenerateKeyPair(String algorithm, int bits) Generates a new key pair.
-
Field Details
-
SSH2_RSA
- See Also:
-
ECDSA
- See Also:
-
ED25519
- See Also:
-
ED448
- See Also:
-
-
Constructor Details
-
SshKeyPairGenerator
public SshKeyPairGenerator()
-
-
Method Details
-
generateKeyPair
Generate a new key pair using the default bit size.- Parameters:
algorithm-- Returns:
- Throws:
IOExceptionSshException
-
generateKeyPair
public static SshKeyPair generateKeyPair(String algorithm, int bits) throws IOException, SshException Generates a new key pair.- Parameters:
algorithm-bits-- Returns:
- SshKeyPair
- Throws:
IOExceptionSshException
-