1 * 简单对称加密算法之加密 2 * @param String $string 需要加密的字串 3 * @param String $skey 加密EKY 4 * @author Anyon Zou <zoujingli@qq.com> 5 * @date 2013-08-13 19:30 6 * @update 2014-10-10 10:10 7 * @return String 8 */ 9 function encode($string = '', $skey = 'cxphp') { 10 $strArr = str_split(base64_encode($string)); 11 $strCount = count($strArr); 12 foreach (str_split($skey) as $key => $value) 13 $key < $strCount && $strArr[$key].=$value; 14 return str_replace(array('=', '+', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr)); 15 } 16 /** 17 * 简单对称加密算法之解密 18 * @param String $string 需要解密的字串 19 * @param String $skey 解密KEY 20 * @author Anyon Zou <zoujingli@qq.com> 21 * @date 2013-08-13 19:30 22 * @update 2014-10-10 10:10 23 * @return String 24 */ 25 function decode($string = '', $skey = 'cxphp') { 26 $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', '+', '/'), $string), 2); 27 $strCount = count($strArr); 28 foreach (str_split($skey) as $key => $value) 29 $key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0]; 30 return base64_decode(join('', $strArr)); 31 }