Skip to content

Instantly share code, notes, and snippets.

@ryctabo
Created February 25, 2018 23:07
Show Gist options
  • Save ryctabo/ff8aa39080c049ea471a6e3ec5e8f260 to your computer and use it in GitHub Desktop.
Save ryctabo/ff8aa39080c049ea471a6e3ec5e8f260 to your computer and use it in GitHub Desktop.
// Read all bytes from the public key file
Path path = Paths.get(publicKeyFile);
byte[] bytes = Files.readAllBytes(path);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
// Generate the public key object from bytes
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(bytes);
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
// Print public key format
LOG.info(String.format("Public key format: %s", publicKey.getFormat()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment