Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mcrypt_module_open() warning !

Tags:

php

mamp

I am using Mamp server on Mac OSX. I am trying to implement the cryptography in my project for client side cookies. I am getting warning

Warning: mcrypt_module_open() [function.mcrypt-module-open]: Could not open encryption module

I checked in the php.ini file and there is no semicolon in front of the mcrypt extension. Can someone help with this issue.

Thanks in advance

like image 265
user525146 Avatar asked Jun 27 '26 17:06

user525146


2 Answers

The mcrypt module is enabled in your php.ini, otherwise you would get an error message along the lines Call to undefined function.

What it indicates is that the requested cipher method is not available. You have either a typo, or one of the ciphers is not compiled into your version of mcrypt.so.

 mcrypt_module_open('rijndael-256', '', 'ofb', '');   // works

 mcrypt_module_open('wrong', '', '', '');   // generates your error

The manual page and the extra parameters indicate that the libmcrypt on your system might depend on shared modules itself. So you might want to search for another version. Try a MAMP update, or use the pro version that exists for that PHP distribution.

like image 100
mario Avatar answered Jun 29 '26 05:06

mario


I am also using this sample from George Schlassnagles "Advanced PHP Programming" (page 334ff). This code includes some mistakes. As you refer to a static variable I think you have to call it with self::$var.

This one should work:

mcrypt_module_open(self::$cipher, '', self::$mode, '');

Note, that there are some more mistakes like:

  • self::$resettime in the validate() function should obviously be named self::$warning.
  • static $key in functions _encrypt() and _decrypt() should be self::$key
  • $glue in the _package() and the _unpackage functions should be self::$glue
  • function _reissue() is never used
  • $td in function _encrypt() should be $this->td
  • set_cookie in functions set() and logout() should be named setcookie and provided with a path '/' (4th parameter) to use the cookie on your whole website (otherwise if you set the cookie eg on /login/facebook you can not access in /dashboard)
  • $ivsize = mcrypt_get_iv_size($this->td); in _decrypt() should be $ivsize = mcrypt_get_iv_size(self::$cypher, self::$mode);
like image 45
Alexander Taubenkorb Avatar answered Jun 29 '26 05:06

Alexander Taubenkorb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!