Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to undefined function mcrypt_encrypt()

Tags:

php

mcrypt

NOTE: The libraries MCrypt support depend on have not been updated in years and MCrypt should no longer be considered a viable or secure method of encrypting data. What's more, MCrypt has been deprecated in PHP 5, and removed entirely in PHP 7. If you have any code that runs MCrypt you should refactor it to use a more modern encryption library.


Does anyone know why this error message: (Call to undefined function mcrypt_encrypt() ) displays when I run the following code below?

Am I missing some steps perhaps any setting in PHP I have to do before this code can work?

$key = 'password to (en/de)crypt';
$string = 'string to be encrypted';

$test = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key),
            $string, MCRYPT_MODE_CBC, md5(md5($key)));
like image 627
Jin Yong Avatar asked Apr 09 '10 00:04

Jin Yong


People also ask

How do I enable Mcrypt?

You can install Mcrypt from the PHP Source Tree as a module if you choose. Enable the module by adding: 'extension=mcrypt.so' to PHP. ini. Done!

What is Mcrypt PHP extension required?

Basically, mcrypt is a file encryption tool that uses advanced algorithms like AES, TripleDES and so on. The Mcrypt extension is an interface to encrypt the Mcrypt cryptographic library. This extension enables PHP code to use mcrypt.


2 Answers

If you have recently updated to ubuntu 14.04 here is the fix to this problem:

$ sudo mv /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
$ sudo php5enmod mcrypt
$ sudo service apache2 restart
like image 95
flor Avatar answered Nov 10 '22 08:11

flor


What had worked for me with PHP version 5.2.8, was to open up php.ini and allow the php_mcrypt.dll extension by removing the ;, i.e. changing:

;extension=php_mcrypt.dll to extension=php_mcrypt.dll

like image 36
Anthony Forloney Avatar answered Nov 10 '22 07:11

Anthony Forloney