(Java) Get Public Key from Certificate PEM
Loads a certificate from a PEM file and gets the cert's public key. Note: This example requires Chilkat v11.0.0 or greater.
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...
}
}
|