Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

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

Chilkat2 Java
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.PublicKey;

public class ChilkatExample {

    public static void main(String[] args) {
        Cert cert = new Cert();

        try {
            cert.loadFromFile("qa_data/certs/someCert.pem");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

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

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

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