(PHP Extension) Get Base64 Public Key from Private Key
Demonstrates how to get the public key in base64 format from a private key.
<?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");
// Load a private key from base64.
$bd = new CkBinData();
$success = $bd->AppendEncoded('MHQCA....n0Q==','base64');
$privKey = new CkPrivateKey();
$success = $privKey->LoadAnyFormat($bd,'');
if ($success == false) {
print $privKey->lastErrorText() . "\n";
exit;
}
// pubKey is a CkPublicKey
$pubKey = $privKey->GetPublicKey();
if ($privKey->get_LastMethodSuccess() == false) {
print $privKey->lastErrorText() . "\n";
exit;
}
$pubKeyBase64 = $pubKey->getEncoded(true,'base64');
print $pubKeyBase64 . "\n";
?>
|