Search code examples
phpsslencryptionhttpsphp-openssl

Call to undefined function openssl_encrypt


I have a CMS using encryption openssl. I use it for a long time and this method works very well for me.

The problem occurred during the building of the first page by making use of SSL certificate and https connection.

Encyption method code:

$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);
}

now when i connect by https:// i received error:

Fatal error: Call to undefined function openssl_encrypt() in ...

I have no idea how to solve this problem, because I really want to keep this method of encryption.

Is this at all possible? Please, any suggestions, proposals or other cryptographic methods.


Solution

  • Thanks to @Artjom B!. The PHP version changed on https connection. On http is 5.6.19, on https 5.2.17