纯PHP实现的DES加密解密
程序员文章站
2022-05-29 20:25:50
...
des加密:
function des_encrypt($str, $key) { $block = mcrypt_get_block_size('des', 'ecb'); $pad = $block - (strlen($str) % $block); $str .= str_repeat(chr($pad), $pad); return mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB); }
des解密:
function des_decrypt($str, $key) { $str = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB); $len = strlen($str); $block = mcrypt_get_block_size('des', 'ecb'); $pad = ord($str[$len - 1]); return substr($str, 0, $len - $pad); }
上一篇: 分享一个新增备案不关站的代码