PHP ActiveX Requires Chilkat v11.0.0+
PHP ActiveX
Encrypt with RSA-OAEP and AES-128-CBC
See more Email Object Examples
Use this profile when the receiver requires AES-128-CBC content encryption and RSA-OAEP with SHA-256. The SHA-256 settings apply to OAEP and its mask generation function. Use the matching decryption example to inspect the result.
Chilkat PHP ActiveX Downloads
<?php
$success = 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$email = new COM("Chilkat.Email");
$success = $email->LoadEml('message.eml');
if ($success != 1) {
print $email->LastErrorText . "\n";
exit;
}
// Use the recipient's public encryption certificate. Its private key stays with the recipient.
$cert = new COM("Chilkat.Cert");
$success = $cert->LoadFromFile('recipient.cer');
if ($success != 1) {
print $cert->LastErrorText . "\n";
exit;
}
$success = $email->SetEncryptCert($cert);
if ($success != 1) {
print $email->LastErrorText . "\n";
exit;
}
$email->Pkcs7CryptAlg = 'aes';
$email->Pkcs7KeyLength = 128;
$email->OaepPadding = 1;
$email->OaepHash = 'sha256';
$email->OaepMgfHash = 'sha256';
$email->SendEncrypted = 1;
$mail = new COM("Chilkat.MailMan");
$rendered = new COM("Chilkat.BinData");
$success = $mail->RenderToMimeBd($email,$rendered);
if ($success != 1) {
print $mail->LastErrorText . "\n";
exit;
}
$success = $rendered->WriteFile('oaep-encrypted.eml');
if ($success != 1) {
print 'Failed: rendered.WriteFile.' . "\n";
exit;
}
print 'Saved oaep-encrypted.eml.' . "\n";
?>