PHP使用自定义key实现对数据加密解密

// 加密
function encryptStr($str, $key){
$block = mcrypt_get_block_size('des', 'ecb');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
$enc_str = mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
return base64_encode($enc_str);
}
// 解密
function decryptStr($str, $key){
$str = base64_decode($str);
$str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
$block = mcrypt_get_block_size('des', 'ecb');
$pad = ord($str[($len = strlen($str)) - 1]);
return substr($str, 0, strlen($str) - $pad);
}
上一篇:Skyline中加载WMTS地图


下一篇:如何在idea中加载本地中已有的python