The limcrypt extension library is used for encryption and decryption. Read the limcrypt extension library for encryption and decryption. Summary: Mcrypt2.4.7 is a powerful encryption algorithm Extension Library, which includes 22 algorithms, which includes the following algorithms: BlowfishRC2Safer-sk64xteaCast-256RC4Safer-sk128DESRC4-ivSerp
Summary: Mcrypt 2.4.7 is a powerful Extension Library for encryption algorithms. It includes 22 algorithms, including the following algorithms:
Blowfish RC2 Safer-sk64 xtea
Cast-256 RC4 Safer-sk128
DES RC4-iv Serpent
Enigma Rijndael-128 Threeway
Gost Rijndael-192 TripleDES
LOKI97 Rijndael-256 (Twofish)
How to install Mcrypt?
Mcrypt is not included in the standard PHP package, so you need to download it at: ftp://argeas.cs-net.gr/pub/unix/mcrypt. After downloading the SDK, compile it as follows and expand it to PHP:
Download the Mcrypt package.
./Configure -- disable-posix-threads
Cd to your PHP directory.
./Configure-with-mcrypt = [dir] [-- other-configuration-directives]
Make appropriate modifications to the server during PHP installation according to your requirements.
How to use the Mcrypt Extension Library to encrypt data?
First, we will introduce how to use the Mcrypt Extension Library to encrypt data, and then how to use it for decryption. The following code demonstrates this process. first, encrypt the data, display the encrypted data in the browser, and restore the encrypted data to the original string, display it in a browser.
Use Mcrypt to encrypt and decrypt data
// Designate string to be encrypted
$ String = "Applied Cryptography, by Bruce Schneier, is
A wonderful cryptography reference .";
// Encryption/decryption key
$ Key = "Four score and twenty years ago ";
// Encryption Algorithm
$ Cipher_alg = MCRYPT_RIJNDAEL_128;
// Create the initialization vector for added security.
$ Iv = mcrypt_create_iv (mcrypt_get_iv_size ($ cipher_alg,
MCRYPT_MODE_ECB), MCRYPT_RAND );
// Output original string
Print "Original string: $ string
// Encrypt $ string
$ Encrypted_string = mcrypt_encrypt ($ cipher_alg, $ key,
$ String, MCRYPT_MODE_CBC, $ iv );
// Convert to hexadecimal and output to browser
Print "Encrypted string:". bin2hex ($ encrypted_string )."
$ Decrypted_string = mcrypt_decrypt ($ cipher_alg, $ key,
$ Encrypted_string, MCRYPT_MODE_CBC, $ iv );
Print "Decrypted string: $ decrypted_string ";
Execute the above script to generate the following output:
Original string: Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.
Encrypted string: 201734fa06bbfb20e71ecf525f29df58e28f3d9bf541f7ebcecf62b 108bfbab5e
Decrypted string: Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.
The two most typical functions in the above code are mcrypt_encrypt () and mcrypt_decrypt (). Their usage is obvious. We use the "Telegraph cipher book" mode. Mcrypt provides several encryption methods. because each encryption method has specific characters that can affect the password security, we need to understand each mode. For those who have never touched the password system, they may be more interested in the mcrypt_create_iv () function. we will mention the initialization vector (hence, iv) it creates ), this always makes each piece of information independent from each other. Although not all modes require this initialization variable, PHP will give a warning if this variable is not provided in the required mode.