2 function setEncryptCookie($key, $value, $time = 0, $path = '/') {
3 if (trim(SECURE_KEY) == '') {
4 setcookie($key, $value, $time, $path);
6 setcookie($key, encrypt($value), $time, $path);
10 function getEncryptCookie($key) {
11 if ( isset($_COOKIE[$key]) ) {
12 if (trim(SECURE_KEY) == '') {
13 return $_COOKIE[$key];
15 return decrypt($_COOKIE[$key]);
22 function getCookie($key) {
23 if ( isset($_COOKIE[$key]) )
24 return $_COOKIE[$key];
29 function delCookie($key) {
30 setcookie($key, '', $_SERVER['REQUEST_TIME']-300, '/');
33 function encrypt($plain_text) {
34 if ( !function_exists('mcrypt_module_open') ) {
35 return EDencrypt($plain_text, SECURE_KEY);
37 $td = mcrypt_module_open('blowfish', '', 'cfb', '');
38 $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
39 mcrypt_generic_init($td, SECURE_KEY, $iv);
40 $crypt_text = mcrypt_generic($td, $plain_text);
41 mcrypt_generic_deinit($td);
42 return base64_encode($iv.$crypt_text);
45 function decrypt($crypt_text) {
46 if ( !function_exists('mcrypt_module_open') ) {
47 return EDdecrypt($crypt_text, SECURE_KEY);
49 $crypt_text = base64_decode($crypt_text);
50 $td = mcrypt_module_open('blowfish', '', 'cfb', '');
51 $ivsize = mcrypt_enc_get_iv_size($td);
52 $iv = substr($crypt_text, 0, $ivsize);
53 $crypt_text = substr($crypt_text, $ivsize);
54 mcrypt_generic_init($td, SECURE_KEY, $iv);
55 $plain_text = mdecrypt_generic($td, $crypt_text);
56 mcrypt_generic_deinit($td);
61 if ( !function_exists('mb_strlen') ) {
62 function mb_strlen($text, $encode) {
63 if (strtolower($encode) == 'utf-8') {
64 return preg_match_all('%(?:
65 [\x09\x0A\x0D\x20-\x7E] # ASCII
66 | [\xC2-\xDF][\x80-\xBF]# non-overlong 2-byte
67 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
68 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
69 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
70 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
71 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
72 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
80 function keyED($txt,$encrypt_key) {
82 $encrypt_key = md5($encrypt_key);
86 for ($i=0;$i<strlen($txt);$i++) {
87 if ($ctr==strlen($encrypt_key)) $ctr=0;
88 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
95 function EDencrypt($txt,$key) {
97 srand((double)microtime()*1000000);
98 $encrypt_key = md5(rand(0,32000));
102 for ($i=0;$i<strlen($txt);$i++) {
103 if ($ctr==strlen($encrypt_key)) $ctr=0;
104 $tmp.= substr($encrypt_key,$ctr,1) . (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
108 return keyED($tmp,$key);
111 function EDdecrypt($txt,$key) {
113 $txt = keyED($txt,$key);
116 for ($i=0;$i<strlen($txt);$i++) {
117 $md5 = substr($txt,$i,1);
119 $tmp.= (substr($txt,$i,1) ^ $md5);