Sample code for 30+ languages & platforms
Java

Get Certificate Public Key from PEM

See more Certificates Examples

Demonstrates how to load a PEM file containing a certificate and access the 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/pem/my_cert.pem");
    if (success == false) {
        System.out.println(cert.lastErrorText());
        return;
        }

    CkPublicKey pubkey = new CkPublicKey();
    cert.GetPublicKey(pubkey);

    // Examine the public key as XML..
    System.out.println(pubkey.getXml());
  }
}