Skip to content

Instantly share code, notes, and snippets.

@ncurran02
Last active January 21, 2019 11:44
Show Gist options
  • Save ncurran02/10963536cb612d14b529716f40296ddb to your computer and use it in GitHub Desktop.
Save ncurran02/10963536cb612d14b529716f40296ddb to your computer and use it in GitHub Desktop.
public static void generateKey(String username)
{
try
{
KeyPairGenerator pair = KeyPairGenerator.getInstance("RSA");
pair.initialize(2048);
KeyPair keyPair = pair.generateKeyPair();
PublicKey pub = keyPair.getPublic();
PrivateKey pri = keyPair.getPrivate();
byte[] publicData = pub.getEncoded();
byte[] privateData = pri.getEncoded();
Path publicKey = Paths.get(BukkitSSH.instance.keys.getAbsolutePath() + File.separator + username);
Path privateKey = Paths.get(BukkitSSH.instance.keys.getAbsolutePath() + File.separator + "private"
+ File.separator + username);
Files.write(publicKey, Base64.encodeBase64(publicData));
Files.write(privateKey, Base64.encodeBase64(privateData));
}
catch (NoSuchAlgorithmException | IOException e)
{
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment