Last active
October 6, 2020 10:55
-
-
Save Slayug/198d4c8f1edf18ed36d500fe8e638a99 to your computer and use it in GitHub Desktop.
This progam demonstrate the RSA keypair generation, and get the keys as String format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.jcraft.jsch.*; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
class KeyGen { | |
public static void main(String[] arg) { | |
String email = "[email protected]"; | |
JSch jsch = new JSch(); | |
try (ByteArrayOutputStream privateKeyStream = new ByteArrayOutputStream(); | |
ByteArrayOutputStream publicKeyStream = new ByteArrayOutputStream()) { | |
com.jcraft.jsch.KeyPair kpair = com.jcraft.jsch.KeyPair.genKeyPair(jsch, com.jcraft.jsch.KeyPair.RSA); | |
kpair.writePrivateKey(privateKeyStream); | |
kpair.writePublicKey(publicKeyStream, email); | |
System.out.println(privateKeyStream.toString()); | |
System.out.println(publicKeyStream.toString()); | |
kpair.dispose(); | |
} catch (JSchException | IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment