(PHP Extension) RSA Import Public Key from Certificate PEM
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.
<?php
include("chilkat.php");
// Use "chilkat_9_5_0.php" for versions of Chilkat < 10.0.0
$cert = new CkCert();
$success = $cert->LoadFromFile('qa_data/pem/mf_public_rsa.pem');
if ($success == false) {
print $cert->lastErrorText() . "\n";
exit;
}
// pubKey is a CkPublicKey
$pubKey = $cert->ExportPublicKey();
if ($cert->get_LastMethodSuccess() != true) {
print $cert->lastErrorText() . "\n";
exit;
}
$rsa = new CkRsa();
$success = $rsa->ImportPublicKeyObj($pubKey);
if ($success == false) {
print $rsa->lastErrorText() . "\n";
exit;
}
$rsa->put_EncodingMode('base64');
$encryptedStr = $rsa->encryptStringENC('hello',false);
print 'encrypted string = ' . $encryptedStr . "\n";
?>
|