如果您想解密收到的电子邮件,请记住您需要完整的加密消息,包括 mime 头。
<?php
$encrypted = imap_fetchmime($stream, $msg_number, "1", FT_UID);
$encrypted .= imap_fetchbody($stream, $msg_number, "1", FT_UID);
$infile = tempnam("", "enc");
file_put_contents($infile, $encrypted);
$outfile = tempnam("", "dec");
$public = file_get_contents("/path/to/your/cert.pem");
$private = array(file_get_contents("/path/to/your/cert.pem"), "password");
if(openssl_pkcs7_decrypt($infile, $outfile, $public, $private))
{
echo file_get_contents($outfile);
}
else
{
echo "哎呀!解密失败!";
}
@unlink($infile);
@unlink($outfile);
?>