Skip to content

Instantly share code, notes, and snippets.

@ryctabo
Created February 25, 2018 22:50
Show Gist options
  • Save ryctabo/7eaf166d7c2b6266e9874d760b19fd15 to your computer and use it in GitHub Desktop.
Save ryctabo/7eaf166d7c2b6266e9874d760b19fd15 to your computer and use it in GitHub Desktop.
// Read all bytes from the private key file
Path path = Paths.get(privateKeyFile);
byte[] bytes = Files.readAllBytes(path);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
// Generate private key object from bytes
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(bytes);
PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
// Print private key format
LOG.info(String.format("Private key format: %s", privateKey.getFormat()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment