PHP可逆加密/解密函数分享_php技巧_脚本之家

函数源码 复制代码 代码如下: function
encrypt { $prep_code = serialize; $block = mcrypt_get_block_size; if
(($pad = $block – % $block)) < $block) { $prep_code .= str_repeat;
} $encrypt = mcrypt_encrypt(MCRYPT_DES, $key, $prep_code,
MCRYPT_MODE_ECB); return base64_encode; } function decrypt { $str =
base64_decode; $str = mcrypt_decrypt(MCRYPT_DES, $key, $str,
MCRYPT_MODE_ECB); $block = mcrypt_get_block_size; $pad = ord($str[

  • 1]); if ($pad && $pad < $block && preg_match . ‘{‘ . $pad .
    ‘}$/’, $str)) { $str = substr – $pad); } return unserialize; } 调用函数
    复制代码 代码如下: $key = ‘okyo.cn’;
    $data = array(‘id’ => 100, ‘username’ => ‘customer’, ‘password’
    => ‘e10adc3949ba59abbe56e057f20f883e’); $snarr = serialize; $en =
    encrypt; $de = decrypt; echo “加密原型:”; print_r; echo ” 密钥:$key
    加密结果:$en 解密结果:”; print_r;