网上找到各种的都不对,上面贴的这个好像因php版本的问题测试也有各种错误,不知怎么改。
回复讨论(解决方案) 试试这个: http://www.cnblogs.com/wangchuang/archive/2012/04/23/2466002.html
楼上说的这个的测试结果:
notice: uninitialized string offset: 6 in c:\web\project1\web\dec.php on line 148
notice: uninitialized string offset: 7 in c:\web\project1\web\dec.php on line 148
notice: uninitialized string offset: 6 in c:\web\project1\web\dec.php on line 148
notice: uninitialized string offset: 7 in c:\web\project1\web\dec.php on line 148
mdn2iafg6imabkvbi2l+ka==
hello levenphp notice: uninitialized string offset: 6 in c:\web\project1\web\dec.php on line 148 php notice: uninitialized string offset: 7 in c:\web\project1\web\dec.php on line 148 php notice: uninitialized string offset: 6 in c:\web\project1\web\dec.php on line 148 php notice: uninitialized string offset: 7 in c:\web\project1\web\dec.php on line 148
function 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);}function decrypt($str, $key) { $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); }
php5.6.3 通过
据说是与 java 兼容的
你的有 deprecated: function mcrypt_cbc() is deprecated
显然是不能用的
