php - Fatal error: Call to undefined function mcrypt_get_iv_size() in AppServ
Asked Answered
I

4

28

I found a problem when I use mcrypt_get_iv_size function via AppServ.

I try to find a topic that related to solved a problem.

However, I try yo download libmcrypt.dll into symtem32 and edit php.ini by removing a comment from ;extension=php_mcrypt.dll to extension=php_mcrypt.dll. Then restart apache.

Unfortunately, after reload a page to see a result after modify.

It still error as

Fatal error: Call to undefined function mcrypt_get_iv_size() in C:\AppServ\www\folder\index.php on line 36

A function contains following:

class Encryption {
    var $skey     = "SuPerEncKey2010"; // you can change it

    public  function safe_b64encode($string) {

        $data = base64_encode($string);
        $data = str_replace(array('+','/','='),array('-','_',''),$data);
        return $data;
    }

    public function safe_b64decode($string) {
        $data = str_replace(array('-','_'),array('+','/'),$string);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }
        return base64_decode($data);
    }

    public  function encode($value){

        if(!$value){return false;}
        $text = $value;
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->skey, $text, MCRYPT_MODE_ECB, $iv);
        return trim($this->safe_b64encode($crypttext)); 
    }

    public function decode($value){

        if(!$value){return false;}
        $crypttext = $this->safe_b64decode($value); 
        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->skey, $crypttext, MCRYPT_MODE_ECB, $iv);
        return strtolower(trim($decrypttext));
    }
}
Isopod answered 24/12, 2014 at 8:2 Comment(5)
try running php from command prompt, that will give you any error that might be happening during dll load, like missing dlls, missing paths, mixed c++ runtime etc.Boxer
how to do it? can you suggest? i check all dlls and it stored in my computer now. so, i don't know why it still errors.Isopod
make sure you have php in your PATH, then open a Command Prompt, type: php, hit enter. See if there are any errors.Boxer
Thank for the all answers :)Isopod
It's instructive to note that mcrypt_get_iv_size() is deprecated as of PHP 7.1 and removed altogether as of PHP 7.2Late
H
11

in case of php-7:

sudo apt-get install mcrypt php7.1-mcrypt

Hieronymus answered 8/1, 2018 at 12:28 Comment(1)
I have not tried for 7.2. You can try it. by changing the version 7.2 from 7.1.Hieronymus
R
58

On Ubuntu, with PHP 5 and Apache, you have to run:

apt-get install php5-mcrypt
php5enmod mcrypt
service apache2 restart

If you are using PHP 7:

apt install php7.0-mcrypt
Rinarinaldi answered 4/2, 2015 at 10:36 Comment(0)
H
11

in case of php-7:

sudo apt-get install mcrypt php7.1-mcrypt

Hieronymus answered 8/1, 2018 at 12:28 Comment(1)
I have not tried for 7.2. You can try it. by changing the version 7.2 from 7.1.Hieronymus
M
6

http://php.net/manual/en/mcrypt.requirements.php

mcrypt is already build in for PHP 5.3.x for Windows, so you don't need to install libmcrypt.dll on the your server.

It's seems like php_mcrypt.dll extension is not loaded.

Motherhood answered 24/12, 2014 at 8:16 Comment(0)
J
2

I had to install the mcrypt libraries on CentOS 7 x86_64 for the above problem.

Here is what I did to install php-mcrypt & libmcrypt dependencies.

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -ivh epel-release-7-5.noarch.rpm
yum install --enablerepo="epel" php-mcrypt

with user 'root' or sudo

with this, no need to add "extension=php_mcrypt.dll" in php.ini file

Jennine answered 13/8, 2015 at 7:27 Comment(2)
This link is not found ?Saunderson
a later version is available now, epel-release-7-6.noarch.rpmJennine

© 2022 - 2024 — McMap. All rights reserved.