Home > Backend Development > PHP Tutorial > openssl函数在https停无法使用

openssl函数在https停无法使用

WBOY
Release: 2016-06-13 12:47:43
Original
856 people have browsed it

openssl函数在https下无法使用
问题:Linux+apache2+php5的环境下,配置ssl使https可以访问,然后执行测试代码:

<br />
<?php<br />
#ssl-encry.php<br />
$source = "This is encry-content.";<br />
echo "1.Source: $source";<br />
$fp=fopen("/path/to/certificate.crt","r");<br />
$pub_key=fread($fp,8192);<br />
fclose($fp);<br />
openssl_get_publickey($pub_key);<br />
openssl_public_encrypt($source,$crypttext,$pub_key);<br />
echo "2.String crypted: $crypttext";<br />
<br />
$fp=fopen("/path/to/private.key","r");<br />
$priv_key=fread($fp,8192);<br />
fclose($fp);<br />
// $passphrase is required if your key is encoded (suggested)<br />
$passphrase = '';<br />
$res = openssl_get_privatekey($priv_key,$passphrase);<br />
openssl_private_decrypt($crypttext,$newsource,$res);<br />
echo "3.String decrypt : $newsource";<br />
?> <br />
<br />
Copy after login

运行后,页面提示无法连接服务器。
经测试,问题在于openssl_public_encrypt()函数无法执行。
openssl_get_publickey()函数正常通过,但是openssl_public_encrypt()函数却使apache崩掉。

直接后台执行:/path/php -f ssl-encry.php ,只有1、2有结果,第3处空。
Windows环境下测试正常输出。

此种情如何解决?

openssl Apache PHP https
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template