(Java) Load Certificate from .cer and Private Key from .pem
Load a certificate from a .cer and its associated private key from a .pem.
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("C:/certs_and_keys/Certificate.cer");
if (success == false) {
System.out.println(cert.lastErrorText());
return;
}
CkStringBuilder sbPem = new CkStringBuilder();
success = sbPem.LoadFile("C:/certs_and_keys/PrivateKey.pem","utf-8");
if (success == false) {
System.out.println("Failed to load private key PEM");
return;
}
success = cert.SetPrivateKeyPem(sbPem.getAsString());
if (success == false) {
System.out.println(cert.lastErrorText());
return;
}
System.out.println("The certificate and associated private key are now loaded and ready for signing.");
}
}
|