(Java) Get Certificate's Public Key
Loads a certificate from PEM and gets the 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();
String strPem = "-----BEGIN CERTIFICATE----- ...";
boolean success = cert.LoadPem(strPem);
if (success != true) {
System.out.println(cert.lastErrorText());
return;
}
CkPublicKey pubKey = cert.ExportPublicKey();
if (cert.get_LastMethodSuccess() == false) {
System.out.println(cert.lastErrorText());
return;
}
// You can now use the public key object however it is needed,
// and access its various properties and methods..
System.out.println(pubKey.getXml());
}
}
|