Page 1 of 1

openssl_random_pseudo_bytes(0)

Posted: Wed Jul 10, 2019 7:24 pm
by locksdownunder
Hello I have just installed OC and all runs fine on my windows PC using chrome.
On my android phone I get the following fatal error
Call to undefined function openssl_random_pseudo_bytes(0) in ...../system/library/session.php on line 62

I have checked php.ini on the server it has

Code: Select all

extension=openssl.so
;extension=intl.so
extension=pgsql.so
;extension=soap.so
;extension=xsl.so
;extension=yaml.so
;extension=memcached.so
;extension=memcache.so
;extension=gmp.so
;extension=mongo.so
;extension=mongodb.so
extension=php_openssl.dll
PHP = 5.6.4
OC = 3.0.3.2

Re: openssl_random_pseudo_bytes(0)

Posted: Wed Jul 10, 2019 9:23 pm
by Johnathan
This is a pretty common error message I've seen in OpenCart 3.0, due to a switch in the encryption library. There is a fix suggested in the forums here, though I haven't tried this myself:

viewtopic.php?f=198&t=204707&p=740186#p737628

If you prefer instead to try and switch back to the older OpenCart 2.3 version of the encryption library, you can make these edits:

Code: Select all

------------------------------------------------------------------------------
IN:
/system/library/encryption.php

REPLACE:
return strtr(base64_encode(openssl_encrypt($value, 'aes-128-cbc', hash('sha256', $key, true))), '+/=', '-_,');

WITH:
return strtr(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, hash('sha256', hash('sha256', $key, true), true), $value, MCRYPT_MODE_ECB)), '+/=', '-_,');

AND REPLACE:
return trim(openssl_decrypt(base64_decode(strtr($value, '-_,', '+/=')), 'aes-128-cbc', hash('sha256', $key, true)));

WITH:
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, hash('sha256', hash('sha256', $key, true), true), base64_decode(strtr($value, '-_,', '+/=')), MCRYPT_MODE_ECB));
------------------------------------------------------------------------------

Re: openssl_random_pseudo_bytes(0)

Posted: Thu Jul 11, 2019 4:48 pm
by locksdownunder
Unfortunately that modification does not fix the problem.
Note my problem is with "openssl_random" not openssl_encrypt

unless there is some sort of system refresh I need to do?

Re: openssl_random_pseudo_bytes(0)

Posted: Thu Jul 11, 2019 5:08 pm
by ADD Creative
It looks like your OpenSSL PHP extension is not enabled. Your PC probably already has a session cookie, whereas you phone might not. You might find if you delete the cookies in Chrome on your PC you will start getting the same error.

Check your phpinfo() to see if it has OpenSSL support enabled.

Re: openssl_random_pseudo_bytes(0)

Posted: Thu Jul 11, 2019 6:11 pm
by locksdownunder
it appears to be there and enabled
Image

Re: openssl_random_pseudo_bytes(0)

Posted: Thu Jul 11, 2019 7:01 pm
by ADD Creative
That looks correct. Does openssl_random_pseudo_bytes work when in a PHP file on its own? Try something link the code below it you have error reporting on.

Code: Select all

<?php
$randnumber = openssl_random_pseudo_bytes(26);
?>

Re: openssl_random_pseudo_bytes(0)

Posted: Fri Jul 12, 2019 4:20 am
by locksdownunder
The code below runs fine on both PC and android device without any error.

Code: Select all

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$randnumber = openssl_random_pseudo_bytes(26);
echo $randnumber;
?>

Re: openssl_random_pseudo_bytes(0)

Posted: Fri Jul 12, 2019 5:51 pm
by ADD Creative
Did you try deleting the cookies on your PC and refreshing the page? Did same error start then appearing?

Re: openssl_random_pseudo_bytes(0)

Posted: Fri Jul 12, 2019 6:06 pm
by locksdownunder
Yes deleting the cookies now makes the website crash on my PC.
www.locksdownunder.com/shop/

Although the test.php works fine
www.locksdownunder.com/test.php

Re: openssl_random_pseudo_bytes(0)

Posted: Sat Jul 13, 2019 5:22 am
by ADD Creative
Could be you have something in your .htaccess, php.ini or user.ini in the shop folder that causing PHP to be configured differently. Try your test.php in the shop folder.

Re: openssl_random_pseudo_bytes(0)

Posted: Sat Jul 13, 2019 6:47 am
by locksdownunder
Thank you for your persistance
Yes it is the php.ini file in the shop directory causing the problem. If I rename it then my test.php works

Again Thank you!!!!