6

When I try to make a request with POST to a script that has this line:

$decrypted_data = openssl_decrypt($encrypted_data, 'AES-256-CBC', $key);

I get the following error:

Fatal error: Call to undefined function openssl_decrypt() in mypath/usuario_webservice.php on line 11

After some research the common reasons would be entering the wrong name for the function or the openssl extension not being installed on my web server. It turns out that it is installed as I checked with the support. So, what else should I be looking for?

Machavity
  • 30,841
  • 27
  • 92
  • 100
CJ_COIMBRA
  • 319
  • 1
  • 3
  • 13
  • 2
    What php version is installed on the web-server? you need php 5.3+ – jeroen Jan 14 '15 at 18:59
  • 3
    `"It turns out that it is installed as I checked with the support."` Maybe support doesn't know what they're talking about. Make a PHP page with ``, run it, and look through it to see for yourself whether its installed or not. – developerwjk Jan 14 '15 at 18:59
  • 3
    the openssl module needs to be both installed AND activated. Support probably just confirmed that it's installed but never checked that it's turned on, use `` and see if the module is in fact being used. – iam-decoder Jan 14 '15 at 19:01
  • @jeroen the version we got here is 5.2.17. I might have misunderstood but the documentation says I could use it from php 4.3.2. I read it here. http://php.net/manual/en/openssl.requirements.php – CJ_COIMBRA Jan 14 '15 at 19:02
  • 1
    Not according to this page: http://php.net/manual/en/function.openssl-decrypt.php. Note that this is specific to the function you are trying to use. – jeroen Jan 14 '15 at 19:03
  • @iamde_coder I got both the --with-openssl in Configure Command and OpenSSL support enabled in OpenSSL section. Where could I check this activation? – CJ_COIMBRA Jan 14 '15 at 19:08
  • 1
    @jeroen Well maybe this is it then. So it is possible to have support for the extension but not for some specific methods? – CJ_COIMBRA Jan 14 '15 at 19:09
  • @CJ_COIMBRA Ask the support if they can upgrade your php version to 5.4, since 5.4 is already stable. – Charlotte Dunois Jan 14 '15 at 19:31
  • Copying libeay32.dll and ssleay32.dll from PHP-root folder to Apache/bin folder and restarted Apache solved my problem. – endo64 Sep 08 '17 at 07:33

4 Answers4

15

I am posting this as it might be helpful to some.

  • Check extension=php_openssl.dll is enabled in your php.ini.
  • Check extension_dir is pointed correctly in php.ini.

If you have recently upgraded your php version and not your Apache then it might be a possibility that correct libeay32.dlland ssleay32.dll are not being read which is a requirement for openssl or some version mismatch is happening.

  • Get latest version of libeay32.dlland ssleay32.dll or copy it from your php directory say C:\php and overwrite the files in your Apache\bin say C:\Apache24\bin directory.

Hope this will help.

Kumar Sambhav Pandey
  • 1,713
  • 4
  • 22
  • 33
  • I download latest libeay32 and ssleay32 dll and restart apache and it works, thanks – Wasim A. Sep 14 '16 at 09:41
  • For those who are still looking into this, note that since version 1.1.0, the library names have changed. libeay32.dll becomes libcrypto-1_1.dll and ssleay32.dll becomes libssl-1_1.dll. As indicated in this answer, both files should be in your PHP directory. – Will May 01 '20 at 14:59
3

Enable this extension in your php.ini file by removing semicolon

extension=php_openssl.dll

Restart your Apache server and retry
Hope that helps :)

Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
  • 2
    OP had to contact support, so I'm assuming he is having this problem on the hosting server, and may not have access to the php.ini file (depending on the type of hosting they have) so this post may prove to be incorrect. – iam-decoder Jan 14 '15 at 19:03
2

i had this problem so i just used Crypt_AES by phpseclib:

<?php
include('Crypt/AES.php');

$cipher = new Crypt_AES(); // it's cbc by default
$cipher->setKeyLength(256);
$cipher->setKey('abcdefghijklmnopijklmnopqrstuvwxyz3456');

$size = 10 * 1024;
$plaintext = str_repeat('a', $size);

echo $cipher->decrypt($cipher->encrypt($plaintext));
?>
0

What solved it for me is upgrading Apache from 2.4.27 to 2.4.53.

I am using Wampserver 3.2.8 on Win64. php_openssl was on in all ini files.

Meddie
  • 571
  • 1
  • 7
  • 22