public class SshKeyPairGenerator extends 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 String |
ECDSA |
static String |
ED25519 |
static String |
ED448 |
static String |
RSA_SHA2_256 |
static String |
RSA_SHA2_512 |
static String |
SSH1_RSA |
static String |
SSH2_DSA |
static String |
SSH2_RSA |
Constructor and Description |
---|
SshKeyPairGenerator() |
Modifier and Type | Method and Description |
---|---|
static SshKeyPair |
generateKeyPair() |
static SshKeyPair |
generateKeyPair(String algorithm) |
static SshKeyPair |
generateKeyPair(String algorithm,
int bits)
Generates a new key pair.
|
public static final String SSH1_RSA
public static final String SSH2_RSA
public static final String RSA_SHA2_256
public static final String RSA_SHA2_512
public static final String SSH2_DSA
public static final String ECDSA
public static final String ED25519
public static final String ED448
public static SshKeyPair generateKeyPair(String algorithm, int bits) throws IOException, SshException
algorithm
- bits
- IOException
SshException
public static SshKeyPair generateKeyPair() throws IOException, SshException
IOException
SshException
public static SshKeyPair generateKeyPair(String algorithm) throws IOException, SshException
IOException
SshException
Copyright © 2024. All rights reserved.