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

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

my $cert = Chilkat2::Cert->new;
my $success = $cert->LoadFromFile('C:/certs_and_keys/Certificate.cer');
if (!$success) {
    print $cert->LastErrorText, "\n";
    exit;
}

my $sbPem = Chilkat2::StringBuilder->new;
$success = $sbPem->LoadFile('C:/certs_and_keys/PrivateKey.pem', 'utf-8');
if (!$success) {
    print "Failed to load private key PEM\n";
    exit;
}

$success = $cert->SetPrivateKeyPem($sbPem->GetAsString());
if (!$success) {
    print $cert->LastErrorText, "\n";
    exit;
}

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