sshj
sshj copied to clipboard
If this can generate public and private key pairs?
trafficstars
If this can generate public and private key pairs
@Laggar Please explain what you want to do.
Is there a convenience method to generate a public and private ssh key pair? Similar to the following one offered by JSch: http://www.jcraft.com/jsch/examples/KeyGen.java.html
@grahamrb - you could have a look at this example which isn't strictly linked to SSHJ but works with it.
You can generate a key pair with this snippet:
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
KeyPair pair = keyGen.generateKeyPair();
keyProvider = new KeyPairWrapper(pair);
Buffer.PlainBuffer buf = new Buffer.PlainBuffer().putPublicKey(pair.getPublic());
publicKey = "ssh-rsa " + Base64.encodeBytes(buf.array(), buf.rpos(), buf.available()) + " [email protected]";
You can then authenticate using the keyProvider:
sshClient.auth("opc", List.of(new AuthPublickey(keyProvider)));