Mcrypt reversible encryption algorithm in PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:09:50
Original
706 people have browsed it

Mcrypt reversible encryption algorithm in PHP

$td = mcrypt_module_open(MCRYPT_DES,'','ecb',''); //Use 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);

//Decryption
$decrypted = mdecrypt_generic($td, $encrypted);

//End
mcrypt_generic_deinit($td);

mcrypt_module_close($td);

//After decryption, there may be subsequent ones that need to be removed
echo trim($decrypted) . "n";

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629707.htmlTechArticleMcrypt reversible encryption algorithm in PHP?php tutorial$td = mcrypt_module_open(MCRYPT_DES,'','ecb', ''); //Use MCRYPT_DES algorithm, ecb mode $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($t...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template