PHP encryption 3DES error Calltoundefinedfunction: mcrypt_module_open () How to Solve _ php instance

Source: Internet
Author: User
Tags crypt
This article mainly introduces how to solve Calltoundefinedfunction: mcrypt_module_open () Error reported by PHP encryption 3DES. If you need more information, refer to this article. I am also a beginner in PHP, after learning about the basic principles of php through w3cschool, you can start writing. But it is still a cainiao.

No matter whether the 3DES encryption method is correct or not, the method is online. When running, an error is reported, killing the younger brother. Finally, I found a method.

<? Php/*** PHP version 3DES encryption/Decryption class ** can be compatible with java's 3DES (DESede) encryption method ** @ Author: Luo Hui (farmer. luo at gmail.com) ** @ version: V0.1 2008.12.04 **/class Crypt3Des {public $ key = "01234567890123456789012345678912"; public $ iv = "23456789"; // like java: private static byte [] myIV = {50, 51, 52, 53, 54, 55, 56, 57}; // encrypt public function encrypt ($ input) {$ input = $ this-> padding ($ input); $ key = base64_decode ($ this-> key); $ td = Mcrypt_module_open (MCRYPT_3DES, '', MCRYPT_MODE_CBC,''); // use the MCRYPT_3DES algorithm and the cbc mode mcrypt_generic_init ($ td, $ key, $ this-> iv ); // initial processing $ data = mcrypt_generic ($ td, $ input); // encrypt mcrypt_generic_deinit ($ td); // end mcrypt_module_close ($ td ); $ data = $ this-> removeBR (base64_encode ($ data); return $ data;} // decrypt public function decrypt ($ encrypted) {$ encrypted = base64_decode ($ encrypted); $ key = base64_decode ($ this-> key); $ Td = mcrypt_module_open (MCRYPT_3DES, '', MCRYPT_MODE_CBC,''); // use the MCRYPT_3DES algorithm, cbc mode mcrypt_generic_init ($ td, $ key, $ this-> iv ); // initial processing $ decrypted = mdecrypt_generic ($ td, $ encrypted); // decrypt mcrypt_generic_deinit ($ td); // end mcrypt_module_close ($ td ); $ decrypted = $ this-> removePadding ($ decrypted); return $ decrypted;} // fill in the password and fill it in multiple public function padding ($ str) of 8) {$ len = 8-strlen ($ str) % 8; for ($ I = 0; $ I <$ l En; $ I ++) {$ str. = chr (0);} return $ str;} // Delete the padding character public function removePadding ($ str) {$ len = strlen ($ str); $ newstr = ""; $ str = str_split ($ str); for ($ I = 0; $ I <$ len; $ I ++) {if ($ str [$ I]! = Chr (0) {$ newstr. = $ str [$ I];} return $ newstr;} // Delete the carriage return and line feed public function removeBR ($ str) {$ len = strlen ($ str ); $ newstr = ""; $ str = str_split ($ str); for ($ I = 0; $ I <$ len; $ I ++) {if ($ str [$ I]! = '\ N' and $ str [$ I]! = '\ R') {$ newstr. = $ str [$ I] ;}return $ newstr ;}// test $ input = "1qaz2ws"; echo "plainText :". $ input."
"; $ Crypt = new Crypt3Des (); echo" Encode: ". $ crypt-> encrypt ($ input )."
"; Echo" Decode: ". $ crypt-> decrypt ($ crypt-> encrypt ($ input);?>

If you do not want to check the code, you can see the following sentence: $ td = mcrypt_module_open (MCRYPT_3DES, '', MCRYPT_MODE_CBC,''); the error is reported.

I searched for a lot of solutions. The correct method should be (for windows only ):

This error occurs when you use the mcrypt_module_open function to decrypt libmcrypt. dll on the server that runs php.

Make the following settings on the server to solve the problem.

Download a php mcrypt module installation package from the Internet. You only need the libmcrypt. dll file (which is usually downloaded on the official website and already exists under the php Directory)

1. Copy libmcrypt. dll to the system32 directory or the extensions directory under the php installation directory.

2. Copy libmcrypt. dll to the bin directory of the apache installation directory.

3. Find the php. ini file in the windows directory and open it.

4. Find; Directory in which the loadable extensions (modules) reside.
Extension_dir = "./" For example: extension_dir = "D: \ php5 \ ext"

In these two rows, you need to find libmcrypt. dll in the directory pointed to by extension_dir, or libmcrypt. dll in the system path.

5. Find the extension = php_mcrypt.dll line and extension = php_iconv.dll line under Windows Extensions, and remove the semicolon

Ps: At the beginning, I started to look at the solution on the Internet. Some said that it was useless to modify the php. ini under the php installation directory. Make sure to modify php. ini in the windows directory!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.