2017/2/20 15:19:58
Category 软件技术 Tag php,des,加密,解密function do_mencrypt($input, $key){
$input = str_replace(" ", "", $input);
$input = str_replace(" ", "", $input);
$input = str_replace(" ", "", $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)));
}
function do_mdecrypt($input, $key){
$input = str_replace(" ", "", $input);
$input = str_replace(" ", "", $input);
$input = str_replace(" ", "", $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));
}