Sample code for 30+ languages & platforms
Perl

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

$cert = chilkat::CkCert->new();
$success = $cert->LoadFromFile("C:/certs_and_keys/Certificate.cer");
if ($success == 0) {
    print $cert->lastErrorText() . "\r\n";
    exit;
}

$sbPem = chilkat::CkStringBuilder->new();
$success = $sbPem->LoadFile("C:/certs_and_keys/PrivateKey.pem","utf-8");
if ($success == 0) {
    print "Failed to load private key PEM" . "\r\n";
    exit;
}

$success = $cert->SetPrivateKeyPem($sbPem->getAsString());
if ($success == 0) {
    print $cert->lastErrorText() . "\r\n";
    exit;
}

print "The certificate and associated private key are now loaded and ready for signing." . "\r\n";