3

我不完全理解,一些文档或帮助将不胜感激:)

使用 PHP 我使用 ezcomponents Mail 对象创建了一个 MIME。但我不明白的是:

您是否通过使用openssl_pkcs7_sign对原始 MIME 进行签名来创建 S/MIME 消息?还是您从头开始创建 S/MIME 并在完成后对其进行签名?

当我试图理解正确的做事方式时,请多多包涵。

编辑:找到这段代码来更好地说明我的问题

<?
// Setup mail headers.
$headers = array("To" => "someone@nowhere.net",
     "From" => "noone@somewhere.net",
     "Subject" => "A signed and encrypted message.");

// Sign the message first
openssl_pkcs7_sign("msg.txt","signed.txt",
     "signing_cert.pem",array("private_key.pem",
     "password"),array());

// Get the public key certificate.
$pubkey = file_get_contents("cert.pem");

//encrypt the message, now put in the headers.
openssl_pkcs7_encrypt("signed.txt", "enc.txt",
     $pubkey,$headers,0,1);

$data = file_get_contents("enc.txt");

// separate header and body, to use with mail function
//  unfortunate but required, else we have two sets of headers
//  and the email client doesn't decode the attachment
$parts = explode("\n\n", $data, 2);

// send mail (headers in the Headers parameter will override those
//  generated for the To & Subject parameters)
mail($mail, $subject, $parts[1], $parts[0]);
?>
4

1 回答 1

2

省去很多麻烦,并通过专为该工作设计的 MTA 过滤器(例如Gnu Anubis(SMTP 代理)或实施 milter )路由您需要签名的消息

于 2011-06-03T09:04:02.680 回答