Skip to content

Instantly share code, notes, and snippets.

@luismoramedina
Created June 2, 2015 14:24
Show Gist options
  • Save luismoramedina/a3adec531e8028679377 to your computer and use it in GitHub Desktop.
Save luismoramedina/a3adec531e8028679377 to your computer and use it in GitHub Desktop.
Extracts the public key from a x509 certificate.
CertificateFactory x509 = CertificateFactory.getInstance("X509");
FileInputStream inStream = new FileInputStream(CERTIFICATE_PATH);
Certificate certificate = x509.generateCertificate(inStream);
byte[] encoded = certificate.getPublicKey().getEncoded();
FileOutputStream fileOutputStream = new FileOutputStream("c:/data/temp/phoenix-public-key.bin");
fileOutputStream.write(encoded);
fileOutputStream.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment