How to encrypt and decrypt the Mcrypt extension Library

Source: Internet
Author: User
Tags mcrypt

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 ???? PanamaSaferplus Wake ?? 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 the download, follow the following method to compile and expand it to PHP :?? Download the Mcrypt package.
???? Gunzipmcrypt-x.x.x.tar.gz ???? Tar -xvfmcrypt-x.x.x.tar ????. /Configure -- disable-posix-threads ???? Make ???? Make install ???? Cd to your PHP directory .????. /Configure-with-mcrypt = [dir] [-- other-configuration-directives] ??? Make ???? Make install ?? 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 ???? ";???? $ Decrypted_string = mcrypt_decrypt ($ cipher_alg, $ key ,???? $ Encrypted_string, MCRYPT_MODE_CBC, $ iv );???? Print "Decrypted string: $ decrypted_string"; ???> ?? Executing the above script will 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 no access to the password system, why? The crypt_create_iv () function is more interested. We will mention the initialization vector (hence, iv) it creates, which can always make each piece of information independent of 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.

Related Article

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.