(PHP Extension) Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem
How to output the public part of a private key:
Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem
<?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");
$pkey = new CkPrivateKey();
// Load the private key from an PEM file:
$success = $pkey->LoadPemFile('private.pem');
if ($success != true) {
print $pkey->lastErrorText() . "\n";
exit;
}
// pubKey is a CkPublicKey
$pubKey = $pkey->GetPublicKey();
if ($pkey->get_LastMethodSuccess() == false) {
print $pkey->lastErrorText() . "\n";
exit;
}
$success = $pubKey->SavePemFile(false,'pubKey.pem');
if ($success != true) {
print $pubKey->lastErrorText() . "\n";
exit;
}
print 'Success.' . "\n";
?>
|