openssl函数在https下无法使用

WBOY
Release: 2016-06-23 14:10:32
Original
1121 people have browsed it

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

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

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

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

此种情如何解决?


回复讨论(解决方案)

openssl_get_publickey()函数正常通过,但是openssl_public_encrypt()函数却使apache崩掉。

查apache错误日志

1、因为apache和php的ssl版本不一致,重新configure相同的ssl,即可运行。
2、执行结果仍然只有1、2两处,第3处为空。
何解?

问题解决:
证书和密钥的权限不一致,全部改为0755就可以了。

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