Mcrypt reversible encryption algorithm in PHP

Source: Internet
Author: User

Mcrypt reversible encryption algorithm in PHP

<?php Tutorial
$TD = Mcrypt_module_open (Mcrypt_des, ', ' ECB ', '); Using the mcrypt_des algorithm, ECB mode

$iv = Mcrypt_create_iv (Mcrypt_enc_get_iv_size ($TD), Mcrypt_rand);
$ks = Mcrypt_enc_get_key_size ($TD);

$key = "ery secret key";//Key
$key = substr (MD5 ($key), 0, $ks);

Mcrypt_generic_init ($TD, $key, $IV); Initial processing

Encryption
$encrypted = Mcrypt_generic ($TD, ' This is very important data ');

End Processing
Mcrypt_generic_deinit ($TD);

Initial decryption processing
Mcrypt_generic_init ($TD, $key, $IV);

Decrypt
$decrypted = Mdecrypt_generic ($TD, $encrypted);

End
Mcrypt_generic_deinit ($TD);

Mcrypt_module_close ($TD);

After decryption, there may be subsequent, need to remove
echo Trim ($decrypted). "N";

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.