mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-09-03 13:51:38 +08:00
删除部分org类库
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace org;
|
||||
|
||||
class Crypt
|
||||
{
|
||||
/**
|
||||
* 加密字符串
|
||||
* @access public
|
||||
*
|
||||
* @param $data
|
||||
* @param string $key 加密key
|
||||
* @param int $expire
|
||||
*
|
||||
* @return string
|
||||
* @internal param string $str 字符串
|
||||
*/
|
||||
public static function encrypt($data, $key, $expire = 0)
|
||||
{
|
||||
$key = md5($key);
|
||||
$data = base64_encode($data);
|
||||
$x = 0;
|
||||
$len = strlen($data);
|
||||
$l = strlen($key);
|
||||
$char = '';
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
if ($x == $l) {
|
||||
$x = 0;
|
||||
}
|
||||
|
||||
$char .= substr($key, $x, 1);
|
||||
$x++;
|
||||
}
|
||||
$str = sprintf('%010d', $expire ? $expire + time() : 0);
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1))) % 256);
|
||||
}
|
||||
return str_replace('=', '', base64_encode($str));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密字符串
|
||||
* @access public
|
||||
*
|
||||
* @param $data
|
||||
* @param string $key 加密key
|
||||
*
|
||||
* @return string
|
||||
* @internal param string $str 字符串
|
||||
*/
|
||||
public static function decrypt($data, $key)
|
||||
{
|
||||
$key = md5($key);
|
||||
$x = 0;
|
||||
$data = base64_decode($data);
|
||||
$expire = substr($data, 0, 10);
|
||||
$data = substr($data, 10);
|
||||
if ($expire > 0 && $expire < time()) {
|
||||
return '';
|
||||
}
|
||||
$len = strlen($data);
|
||||
$l = strlen($key);
|
||||
$char = $str = '';
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
if ($x == $l) {
|
||||
$x = 0;
|
||||
}
|
||||
|
||||
$char .= substr($key, $x, 1);
|
||||
$x++;
|
||||
}
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
|
||||
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
|
||||
} else {
|
||||
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
|
||||
}
|
||||
}
|
||||
return base64_decode($str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user