入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

让人难过的 openssl_pkcs7_encrypt

创建时间:2017-01-19 投稿人: 浏览次数:1028

让人难过的 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:wwwvhostslocalhostmsg.txt";
$enc="D:wwwvhostslocalhostenc.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:wwwvhostslocalhostenc.txt";
$dec="D:wwwvhostslocalhostdecrypted.txt";
openssl_pkcs7_decrypt($enc, $dec, $cert, array( $key, "mm123456"));
$enc=file_get_contents($enc);
echo $enc;
?>
然后,把 $enc PUT给SOCKET。。

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。