PHP Requires Chilkat v11.8.0+
PHP
Extract PKCS7 from MIME and Decrypt
See more MIME Examples
Extracts the base64-encoded PKCS7 body of a MIME message to a file, and then decrypts using Chilkat Crypt2.Chilkat PHP Downloads
<?php
use Chilkat2\Crypt2;
use Chilkat2\Mime;
use Chilkat2\Pem;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$mime = new Mime();
try {
$mime->LoadMimeFile('c:/aaworkarea/EmailInBytes.txt');
$mime->SaveBody('c:/aaworkarea/smime.p7m');
$crypt = new Crypt2();
// The certificate and its private key are in a PEM file. The 2nd argument of LoadPemFile is the
// password of the private key. (Pass an empty string if the private key is not encrypted.)
$pem = new Pem();
$pem->LoadPemFile('c:/aaworkarea/my.pem', 'pemPassword');
$crypt->AddPemSource($pem);
// Indicate the public-key (PKCS7) encryption/decryption should be used:
$crypt->CryptAlgorithm = 'pki';
$inPath = 'c:/aaworkarea/smime.p7m';
$outPath = 'c:/aaworkarea/decrypted.dat';
$crypt->CkDecryptFile($inPath, $outPath);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "Success.\n";