(PHP Extension) Use Base64 RSA Key to Encrypt
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.
<?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");
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$pubkey = new CkPublicKey();
$success = $pubkey->LoadBase64('MIICdgIBADA ... A9PXLk+j5A==');
if ($success != true) {
print $pubkey->lastErrorText() . "\n";
exit;
}
$rsa = new CkRsa();
$success = $rsa->ImportPublicKeyObj($pubkey);
if ($success != true) {
print $rsa->lastErrorText() . "\n";
exit;
}
$rsa->put_EncodingMode('base64');
$encryptedStr = $rsa->encryptStringENC('12345678',false);
print $encryptedStr . "\n";
?>
|