关于在 php 中使用 pkcs7 签署电子邮件的文档,我必须使用先前生成的证书。
在 openssl 中准确生成此示例所需文件的命令是什么? http://www.php.net/manual/it/function.openssl-pkcs7-sign.php
<?php
// the message you want to sign so that recipient can be sure it was you that
// sent it
$data = <<<EOD
You have my authorization to spend $10,000 on dinner expenses.
The CEO
EOD;
// save message to file
$fp = fopen("msg.txt", "w");
fwrite($fp, $data);
fclose($fp);
// encrypt it
if (openssl_pkcs7_sign("msg.txt", "signed.txt", "mycert.pem",
array("file://mycert.pem", "mypassphrase"),
array("To" => "joes@example.com", // keyed syntax
"From: HQ <ceo@example.com>", // indexed syntax
"Subject" => "Eyes only")
)) {
// message signed - send it!
exec(ini_get("sendmail_path") . " < signed.txt");
}
?>
在此先感谢您的帮助。
编辑1:
$prepend = "file:/";
openssl_pkcs7_sign($prepend . realpath(dirname(__FILE__)) . "/text.txt",
$prepend . realpath(dirname(__FILE__)) . "/enc.txt",
$prepend . realpath(dirname(__FILE__)) . "/selfcert.pem",
array($prepend . realpath(dirname(__FILE__)) . "/enc_key.pem", "123456"),
$headers);
我用命令生成了证书文件
openssl req -x509 -days 365 -newkey rsa:1024 -keyout enc_key.pem -out selfcert.pem
仍然得到错误:
警告:openssl_pkcs7_sign():获取私钥时出错...
编辑2:添加前置
也许它与“预先准备”有关?我真的不确定问题是在文件检索还是密钥本身。