PHP Requires Chilkat v11.0.0+
PHP
Export Digital Certificate's Public Key
See more Certificates Examples
The ExportPublicKey method can be called to get a certificate's public key. It can then be saved to any of a number of formats: (1) OpenSSL DER, (2) OpenSSL PEM, (3) RSA DER, (4) XML.Chilkat PHP Downloads
<?php
use Chilkat2\Cert;
use Chilkat2\PublicKey;
$cert = new Cert();
// LoadFromFile will load virtually any certificate format file.
// It will auto-recognize the format and load appropiately.
try {
$cert->LoadFromFile('/Users/chilkat/testData/cer/chilkat.cer');
// Get the public key:
$pubkey = new PublicKey();
$cert->GetPublicKey($pubkey);
// Save to various formats:
$pubkey->SaveDerFile(false, '/Users/chilkat/testData/pubkeys/chilkat_pkcs8.der');
$pubkey->SavePemFile(false, '/Users/chilkat/testData/pubkeys/chilkat.pem');
$pubkey->SaveDerFile(true, '/Users/chilkat/testData/pubkeys/chilkat_pkcs1.der');
$pubkey->SaveXmlFile('/Users/chilkat/testData/pubkeys/chilkat.xml');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "Public key exported to all file formats.\n";