(PHP ActiveX) 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
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.Cert')
$cert = new COM("Chilkat.Cert");
$success = $cert->LoadFromFile('qa_data/pem/mf_public_rsa.pem');
if ($success == 0) {
print $cert->LastErrorText . "\n";
exit;
}
// pubKey is a Chilkat.PublicKey
$pubKey = $cert->ExportPublicKey();
if ($cert->LastMethodSuccess != 1) {
print $cert->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 == 0) {
print $rsa->LastErrorText . "\n";
exit;
}
$rsa->EncodingMode = 'base64';
$encryptedStr = $rsa->encryptStringENC('hello',0);
print 'encrypted string = ' . $encryptedStr . "\n";
?>
|