我有一个使用加密 openssl 的 CMS。我使用了很长时间,这种方法对我来说效果很好。
问题出现在使用SSL证书和https连接构建首页时。
加密方法代码:
$crypt = array(
'key' => 'zM6XJLg1wKWvvzhoWHM7',
'method' => 'AES-256-CBC',
'iv' => 'gantedos',
);
function eco_encrypt($string) {
global $crypt;
$output = false;
// hash
$key = hash('sha256', $crypt['key']);
$iv = substr(hash('sha256', $crypt['iv']), 0, 16);
$output = openssl_encrypt($string, $crypt['method'], $key, 0, $iv);
$output = base64_encode($output);
return $output;
}
function eco_decrypt($string) {
global $crypt;
$output = false;
$key = hash('sha256', $crypt['key']);
$iv = substr(hash('sha256', $crypt['iv']), 0, 16);
$output = openssl_decrypt(base64_decode($string), $crypt['method'], $key, 0, $iv);
return $output;
}
function eco_encrypt_md5($string) {
global $crypt;
$output = false;
$key = hash('sha256', $crypt['key']);
$iv = substr(hash('sha256', $crypt['iv']), 0, 16);
$output = openssl_encrypt($string, $crypt['method'], $key, 0, $iv);
$output = base64_encode($output);
return md5($output);
}
现在当我通过 https://连接时我收到错误:
fatal error :在 ... 中调用未定义的函数 openssl_encrypt()
我不知道如何解决这个问题,因为我真的很想保留这种加密方式。
这有可能吗?请提出任何建议、提案或其他加密方法。
最佳答案
感谢@Artjom B! PHP 版本在 https 连接上发生了变化。 在 http 上是 5.6.19,在 https 上是 5.2.17
关于php - 调用未定义函数 openssl_encrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39933605/