Sample code for 30+ languages & platforms
Java

Get Public Key from Certificate PEM

See more Certificates Examples

Loads a certificate from a PEM file and gets the cert's public key.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkCert cert = new CkCert();

    success = cert.LoadFromFile("qa_data/certs/someCert.pem");
    if (success == false) {
        System.out.println(cert.lastErrorText());
        return;
        }

    // Get the certificate's public key:
    CkPublicKey pubkey = new CkPublicKey();
    cert.GetPublicKey(pubkey);

    System.out.println(pubkey.getPem(false));

    // OK.. we have the public key which can be used in other Chilkat classes/methods...
  }
}