Posted in PHP onJuly 12, 2016
本文实例讲述了PHP简单实现DES加密解密的方法。分享给大家供大家参考,具体如下:
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); }
PHP简单实现DES加密解密的方法
- Author -
dotcoo声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@