Skip to content

Instantly share code, notes, and snippets.

@ryctabo
Last active February 4, 2018 23:20
Show Gist options
  • Save ryctabo/3e3d83e43da30454cf0f103407d97e97 to your computer and use it in GitHub Desktop.
Save ryctabo/3e3d83e43da30454cf0f103407d97e97 to your computer and use it in GitHub Desktop.
Save pair keys in text plain
Base64.Encoder encoder = Base64.getEncoder();
try (FileWriter out = new FileWriter(fileName)) {
out.write("----BEGIN RSA PRIVATE KEY----");
out.write("\n");
out.write(encoder.encodeToString(prviateKey.getEncoded()));
out.write("\n");
out.write("----END RSA PRIVATE KEY----");
out.write("\n");
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
Base64.Encoder encoder = Base64.getEncoder();
try (FileWriter out = new FileWriter(fileName)) {
out.write("----BEGIN RSA PUBLIC KEY----");
out.write("\n");
out.write(encoder.encodeToString(publicKey.getEncoded()));
out.write("\n");
out.write("----END RSA PUBLIC KEY----");
out.write("\n");
} catch (IOException ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment