openssl函数在https下无法使用
问题: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";
?>