让人难过的 openssl_pkcs7_encrypt
用PHP.NET的范例,没有加密结果,也没有报错信息,而openssl_pkcs7_sign()函数则返回 error opening input file msg.txt! 反复看了,没有错误,但是为什么会提示没有打开 msg.txt 文件????????
google了一下,一个帖子中提到在 windows 中只有 绝对路径才有效,照做了,有了结果。 真的让人崩溃,浪费了好多时间。
//============================================================//
<?php
//定义邮件头
$header = array("To" => "",
"From" => "HQ <>",
"Reply-to" => "",
"Subject" => "Eyes only");
//提取证书和需要的文件
$cert = file_get_contents("cacert.pem");
$source = 'D:\www\vhosts\localhost\msg.txt';
$enc='D:\www\vhosts\localhost\enc.txt';
//加密
openssl_pkcs7_encrypt($source, $enc, $cert, null); // $header 替换 null
echo file_get_contents($enc);
//解密 $cert = file_get_contents("cacert.pem");
$key = file_get_contents("cakey.pem");
$enc='D:\www\vhosts\localhost\enc.txt';
$dec='D:\www\vhosts\localhost\decrypted.txt';
openssl_pkcs7_decrypt($enc, $dec, $cert, array( $key, "mm123456"));
$enc=file_get_contents($enc);
echo $enc;
?>
然后,把 $enc PUT给SOCKET。。