我有这个代码:
$fp = fopen($unenc_path, "w");
fwrite($fp, $msg);
fclose($fp);
$easy_access_emails = 'person@##.com';
$headers = "From: support@##.com <support@##.com>\n" .
"Reply-to: support@##.com\n" .
"Subject: " . $subject . "\n";
$key = implode("", file("../newcert.pem"));
$ArrayMessageProperties = explode("\n", $headers);
$unenc_path = '..\\tmp\\'. preg_replace('/[^0-9]/','', microtime()) . rand(0,1000) . "msg.txt";
$enc_path = '..\\tmp\\'. preg_replace('/[^0-9]/','', microtime()) . rand(0,1000) . "enc.txt";
if (openssl_pkcs7_encrypt($unenc_path, $enc_path, $key, $ArrayMessageProperties))
{
$info = file_get_contents($enc_path);
foreach ($easy_access_emails as $email)
{
mail($email, $subject, $info, $headers);
}
} else {
die("Failed Encryption");
}
在我的本地开发环境(运行 LAMP 的 Macbook)上可以正常工作。我将其移至 Windows 服务器进行测试,现在openssl_pkcs7_encrypt
每次都失败。我认为这是一个权限问题,因为该函数需要写入$enc_path
; 但我已将 Windows 服务器上的目录尽可能地打开。(将完全控制设置为几乎每个可能与它有关的用户/组。任何人都知道调试它的好方法吗?看起来该函数在失败时只是返回 false 而没有说明原因。
经过进一步调查,该脚本似乎具有对该目录的写访问权限。它写入 $unenc_path 没问题,只是在调用openssl_pkcs7_encrypt
.
另一个更新:我正在使用 filemon 来观察一些请求,我看到它打开并写入未加密的文件,但即使尝试写入加密文件也没有输出。
还添加了加载密钥的行。我已经通过回显它来验证它正在加载,它似乎很好。
另一个更新: 再次观看 filemon,大约在它应该调用的时间openssq_pkcs7_encrypt
我看到一个条目,它正在 Windows tmp 目录中寻找未加密的消息。
w3wp.exe:4172 C:\windows\system32\tmp\04277530010012336..msg.txt
PATH NOT FOUND Options: Open Access: Read