(Java) Get Public Key from Certificate PEM
Loads a certificate from a PEM file and gets the cert's public key.
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[])
{
CkCert cert = new CkCert();
boolean success = cert.LoadFromFile("qa_data/certs/someCert.pem");
if (success != true) {
System.out.println(cert.lastErrorText());
return;
}
// Get the certificate's public key:
CkPublicKey pubkey = cert.ExportPublicKey();
if (cert.get_LastMethodSuccess() != true) {
System.out.println(cert.lastErrorText());
return;
}
System.out.println(pubkey.getPem(false));
// OK.. we have the public key which can be used in other Chilkat classes/methods...
}
}
|