无为清净楼资源网 Design By www.qnjia.com
复制代码 代码如下:
// +----------------------------------------------------------------------+
// | Willko Framework |
// +----------------------------------------------------------------------+
// | Copyright (c) 2008-2009 Willko Cheng |
// +----------------------------------------------------------------------+
// | Authors: Willko Cheng <willko@foxmail.com> |
// +----------------------------------------------------------------------+
// $string 明文 或 密文
// $isEncrypt 是否加密
// $key 密匙
// 采用SHA1生成密匙簿,超过300个字符使用ZLIB压缩
function dencrypt($string, $isEncrypt = true, $key = KEY_SPACE) {
if (!isset($string{0}) || !isset($key{0})) {
return false;
}

$dynKey = $isEncrypt ? hash('sha1', microtime(true)) : substr($string, 0, 40);
$fixedKey = hash('sha1', $key);

$dynKeyPart1 = substr($dynKey, 0, 20);
$dynKeyPart2 = substr($dynKey, 20);
$fixedKeyPart1 = substr($fixedKey, 0, 20);
$fixedKeyPart2 = substr($fixedKey, 20);
$key = hash('sha1', $dynKeyPart1 . $fixedKeyPart1 . $dynKeyPart2 . $fixedKeyPart2);

$string = $isEncrypt ? $fixedKeyPart1 . $string . $dynKeyPart2 : (isset($string{339}) ? gzuncompress(base64_decode(substr($string, 40))) : base64_decode(substr($string, 40)));

$n = 0;
$result = '';
$len = strlen($string);

for ($n = 0; $n < $len; $n++) {
$result .= chr(ord($string{$n}) ^ ord($key{$n % 40}));
}
return $isEncrypt ? $dynKey . str_replace('=', '', base64_encode($n > 299 ? gzcompress($result) : $result)) : substr($result, 20, -20);
}
标签:
PHP,加密,解密,dencrypt

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com