(PHP Extension) ZATCA Load Certificate and Private Key from PEM Files
Demonstrates how to load a certificate and private key from a pair of PEM files.
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
// The LoadFromFile method will automatically detect the file format..
$cert = new CkCert();
$success = $cert->LoadFromFile('qa_data/zatca/cert.pem');
if ($success != true) {
print $cert->lastErrorText() . "\n";
exit;
}
print $cert->subjectCN() . "\n";
// Load the private key.
$privKey = new CkPrivateKey();
$success = $privKey->LoadPemFile('qa_data/zatca/ec-secp256k1-priv-key.pem');
if ($success != true) {
print $privKey->lastErrorText() . "\n";
exit;
}
print 'Key Type: ' . $privKey->keyType() . "\n";
// Associate the private key with the certificate.
$success = $cert->SetPrivateKey($privKey);
if ($success != true) {
print $cert->lastErrorText() . "\n";
exit;
}
print 'Success.' . "\n";
?>
|