首页 >后端开发 >php教程 >PHP浣跨敤DES杩涜鍔犲瘑涓庤В瀵嗙殑鏂规硶_PHP鏁欑▼ | 甯涔嬪

PHP浣跨敤DES杩涜鍔犲瘑涓庤В瀵嗙殑鏂规硶_PHP鏁欑▼ | 甯涔嬪

WBOY
WBOY原创
2016-07-20 11:17:291083浏览

 銆€銆€浠g爜濡備笅:

銆€銆€//$input - stuff to decrypt

銆€銆€//$key - the secret key to use

銆€銆€function do_mencrypt($input, $key)

銆€銆€{

銆€銆€$input = str_replace(""n", "", $input);

銆€銆€$input = str_replace(""t", "", $input);

銆€銆€$input = str_replace(""r", "", $input);

銆€銆€$key = substr(md5($key), 0, 24);

銆€銆€$td = mcrypt_module_open('tripledes', '', 'ecb', '');

銆€銆€$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);

銆€銆€mcrypt_generic_init($td, $key, $iv);

銆€銆€$encrypted_data = mcrypt_generic($td, $input);

銆€銆€mcrypt_generic_deinit($td);

銆€銆€mcrypt_module_close($td);

銆€銆€return trim(chop(base64_encode($encrypted_data)));

銆€銆€}

銆€銆€//$input - stuff to decrypt

銆€銆€//$key - the secret key to use

銆€銆€function do_mdecrypt($input, $key)

銆€銆€{

銆€銆€$input = str_replace(""n", "", $input);

銆€銆€$input = str_replace(""t", "", $input);

銆€銆€$input = str_replace(""r", "", $input);

銆€銆€$input = trim(chop(base64_decode($input)));

銆€銆€$td = mcrypt_module_open('tripledes', '', 'ecb', '');

銆€銆€$key = substr(md5($key), 0, 24);

銆€銆€$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);

銆€銆€mcrypt_generic_init($td, $key, $iv);

銆€銆€$decrypted_data = mdecrypt_generic($td, $input);

銆€銆€mcrypt_generic_deinit($td);

銆€銆€mcrypt_module_close($td);

銆€銆€return trim(chop($decrypted_data));

銆€銆€}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/372011.htmlTechArticle浠g爜濡備笅: //$input - stuff to decrypt //$key - the secret key to use function do_mencrypt($input, $key) { $input = str_replace(n, , $input); $input = str_replace(t, , $input);...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn