Sample code for 30+ languages & platforms
Perl

ZATCA Load Certificate and Private Key from PEM Files

See more ZATCA Examples

Demonstrates how to load a certificate and private key from a pair of PEM files.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

# The LoadFromFile method will automatically detect the file format..
$cert = chilkat::CkCert->new();
$success = $cert->LoadFromFile("qa_data/zatca/cert.pem");
if ($success != 1) {
    print $cert->lastErrorText() . "\r\n";
    exit;
}

print $cert->subjectCN() . "\r\n";

# Load the private key.
$privKey = chilkat::CkPrivateKey->new();
$success = $privKey->LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem");
if ($success != 1) {
    print $privKey->lastErrorText() . "\r\n";
    exit;
}

print "Key Type: " . $privKey->keyType() . "\r\n";

# Associate the private key with the certificate.
$success = $cert->SetPrivateKey($privKey);
if ($success != 1) {
    print $cert->lastErrorText() . "\r\n";
    exit;
}

print "Success." . "\r\n";