Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Get Public Key from Certificate PEM

See more Certificates Examples

Loads a certificate from a PEM file and gets the cert's public key.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Cert;
use Chilkat2\PublicKey;

$cert = new Cert();

try {
    $cert->LoadFromFile('qa_data/certs/someCert.pem');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Get the certificate's public key:
$pubkey = new PublicKey();
$cert->GetPublicKey($pubkey);

echo $pubkey->GetPem(false), "\n";

// OK.. we have the public key which can be used in other Chilkat classes/methods...