Home >Backend Development >PHP Tutorial > openssl函数在https停无法使用
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 />