Sample code for 30+ languages & platforms
PHP ActiveX Requires Chilkat v11.0.0+

Decrypt an S/MIME email and verify its signature

See more Email Object Examples

Register the recipient’s PFX before opening signed-encrypted.eml. This workflow expects both encryption and a signature, so it checks both layers before reading the message. Cryptographic signature validity is one input to a signer-trust decision.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

$email = new COM("Chilkat.Email");
$success = $email->AddPfxSourceFile('recipient.pfx','RECIPIENT_PASSWORD');
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

$success = $email->LoadEml('signed-encrypted.eml');
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

if (($email->ReceivedEncrypted != 1) or ($email->Decrypted != 1)) {
    print 'Expected a successfully decrypted S/MIME envelope.' . "\n";
    exit;
}

if (($email->ReceivedSigned != 1) or ($email->SignaturesValid != 1)) {
    print 'Expected a valid signature inside the envelope.' . "\n";
    exit;
}

//  This message has one signer. Examine its certificate after verification.
$signer = new COM("Chilkat.Cert");
$success = $email->LastSignerCert(0,$signer);
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

print 'Signer certificate: ' . $signer->SubjectDN . "\n";
print 'Recovered subject: ' . $email->Subject . "\n";
print 'Recovered attachments: ' . $email->NumAttachments . "\n";

?>