(PHP ActiveX) Use Base64 RSA Key to Encrypt
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.
<?php
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.PublicKey')
$pubkey = new COM("Chilkat.PublicKey");
$success = $pubkey->LoadBase64('MIICdgIBADA ... A9PXLk+j5A==');
if ($success != 1) {
print $pubkey->LastErrorText . "\n";
exit;
}
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.Rsa')
$rsa = new COM("Chilkat.Rsa");
$success = $rsa->ImportPublicKeyObj($pubkey);
if ($success != 1) {
print $rsa->LastErrorText . "\n";
exit;
}
$rsa->EncodingMode = 'base64';
$encryptedStr = $rsa->encryptStringENC('12345678',0);
print $encryptedStr . "\n";
?>
|