function sys_auth($string, $operation = 'ENCODE', $key = 'amh_key', $expiry = 0)
{
if($operation == 'ENCODE')
$string = urlencode( $string );
$key_length = 4;
$key = md5($key != '' ? $key : 'amh_key');
$fixedkey = md5($key);
$egiskeys = md5(substr($fixedkey, 16, 16));
$runtokey = $key_length ? ($operation == 'ENCODE' ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : '';
$keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));
$string = $operation == 'ENCODE' ? sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));
$i = 0; $result = '';
$string_length = strlen($string);
for ($i = 0; $i < $string_length; $i++){
$result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
}
if($operation == 'ENCODE') {
return $runtokey . base64_encode($result) ;
} else {
if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {
return urldecode( substr($result, 26));
} else {
return '';
}
}
}
加密:$keydata = urlencode(functions::sys_auth($keydata, 'ENCODE', $_SESSION'amh_config'['config_value'], _APIt));
解密:$keydata = json_decode(Functions::sys_auth($keydata, 'DECODE', $_SESSION'amh_config'['config_value']));
Bug天天改,头发日日疏,码字不易,如果有帮助到你,就点击"下方感谢"支持一下把.