public class SshKeyPairGenerator
extends java.lang.Object
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();
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ECDSA |
static java.lang.String |
ED25519 |
static java.lang.String |
SSH2_RSA |
| Constructor and Description |
|---|
SshKeyPairGenerator() |
| Modifier and Type | Method and Description |
|---|---|
static SshKeyPair |
generateKeyPair(java.lang.String algorithm)
Generate a new key pair using the default bit size.
|
static SshKeyPair |
generateKeyPair(java.lang.String algorithm,
int bits)
Generates a new key pair.
|
public static final java.lang.String SSH2_RSA
public static final java.lang.String ECDSA
public static final java.lang.String ED25519
public static SshKeyPair generateKeyPair(java.lang.String algorithm) throws java.io.IOException, SshException
algorithm - java.io.IOExceptionSshExceptionpublic static SshKeyPair generateKeyPair(java.lang.String algorithm, int bits) throws java.io.IOException, SshException
algorithm - bits - java.io.IOExceptionSshExceptionCopyright © 2022. All rights reserved.