Sample code for 30+ languages & platforms
PHP

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 PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Cert;
use Chilkat2\StringBuilder;

$cert = new Cert();
try {
    $cert->LoadFromFile('C:/certs_and_keys/Certificate.cer');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$sbPem = new StringBuilder();
try {
    $sbPem->LoadFile('C:/certs_and_keys/PrivateKey.pem', 'utf-8');
} catch (\Chilkat2\Exception $e) {
    echo "Failed to load private key PEM\n";
    exit;
}

try {
    $cert->SetPrivateKeyPem($sbPem->GetAsString());
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

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