commit | author | age
|
19351a
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 加密解密类 |
|
5 |
*/ |
|
6 |
|
|
7 |
if (!defined('IN_ECS')) |
|
8 |
{ |
|
9 |
die('Hacking attempt'); |
|
10 |
} |
|
11 |
|
|
12 |
|
|
13 |
/** |
|
14 |
* 加密函数 |
|
15 |
* @param string $str 加密前的字符串 |
|
16 |
* @param string $key 密钥 |
|
17 |
* @return string 加密后的字符串 |
|
18 |
*/ |
|
19 |
function encrypt($str, $key = AUTH_KEY) |
|
20 |
{ |
|
21 |
$coded = ''; |
|
22 |
$keylength = strlen($key); |
|
23 |
|
|
24 |
for ($i = 0, $count = strlen($str); $i < $count; $i += $keylength) |
|
25 |
{ |
|
26 |
$coded .= substr($str, $i, $keylength) ^ $key; |
|
27 |
} |
|
28 |
|
|
29 |
return str_replace('=', '', base64_encode($coded)); |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* 解密函数 |
|
34 |
* @param string $str 加密后的字符串 |
|
35 |
* @param string $key 密钥 |
|
36 |
* @return string 加密前的字符串 |
|
37 |
*/ |
|
38 |
function decrypt($str, $key = AUTH_KEY) |
|
39 |
{ |
|
40 |
$coded = ''; |
|
41 |
$keylength = strlen($key); |
|
42 |
$str = base64_decode($str); |
|
43 |
|
|
44 |
for ($i = 0, $count = strlen($str); $i < $count; $i += $keylength) |
|
45 |
{ |
|
46 |
$coded .= substr($str, $i, $keylength) ^ $key; |
|
47 |
} |
|
48 |
|
|
49 |
return $coded; |
|
50 |
} |
|
51 |
|
|
52 |
?> |