PHP Requires Chilkat v11.0.0+
PHP
Sign an EML using RSA-PSS and SHA-256
See more Email Object Examples
Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.
Chilkat PHP Downloads
<?php
use Chilkat2\BinData;
use Chilkat2\Cert;
use Chilkat2\Email;
use Chilkat2\MailMan;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$email = new Email();
try {
$email->LoadEml('message.eml');
$cert = new Cert();
$cert->LoadPfxFile('signer.pfx', 'PFX_PASSWORD');
$email->SetSigningCert($cert);
$email->SigningAlg = 'pss';
$email->SigningHashAlg = 'sha256';
$email->SendSigned = true;
$mail = new MailMan();
$mail->OpaqueSigning = false;
$rendered = new BinData();
$mail->RenderToMimeBd($email, $rendered);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
try {
$rendered->WriteFile('signed.eml');
} catch (\Chilkat2\Exception $e) {
echo "Failed: rendered.WriteFile.\n";
exit;
}
echo "Saved signed.eml.\n";