从 MIME 创建 S/MIME?

发布于 2024-11-13 07:43:21 字数 1572 浏览 5 评论 0原文

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

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

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

当我尝试理解正确的做事方式时,请耐心等待。

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

<?
// Setup mail headers.
$headers = array("To" => "[email protected]",
     "From" => "[email protected]",
     "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]);
?>

I don't completely understand and some documentation or help would be appreciated greatly :)

Using PHP I create a MIME by using ezcomponents Mail object. But what I do not understand is:

Do you create an S/MIME message from a original MIME by signing it with openssl_pkcs7_sign ? or do you create an S/MIME from scratch and sign it when its done?

Please bear with me as I try to understand the correct way of doing things.

EDIT: Found this piece of code to illustrate my question better

<?
// Setup mail headers.
$headers = array("To" => "[email protected]",
     "From" => "[email protected]",
     "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]);
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦屿孤独相伴 2024-11-20 07:43:21

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

Save yourself a lot of pain and route the messages you need signed through a MTA filter that is designed for the job, e.g. Gnu Anubis (SMTP proxy) or implement a milter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文