PSR规范调整

This commit is contained in:
thinkphp
2015-10-04 13:05:15 +08:00
parent 1cfb3704c6
commit 27e724bb3c
135 changed files with 9426 additions and 11556 deletions

View File

@@ -11,7 +11,8 @@
namespace think;
class Crypt {
class Crypt
{
/**
* 加密字符串
* @access public
@@ -19,20 +20,24 @@ class Crypt {
* @param string $key 加密key
* @return string
*/
static public function encrypt($data,$key,$expire=0){
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);
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++) {
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));
@@ -45,27 +50,31 @@ class Crypt {
* @param string $key 加密key
* @return string
*/
static public function decrypt($data,$key){
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()) {
$expire = substr($data, 0, 10);
$data = substr($data, 10);
if ($expire > 0 && $expire < time()) {
return '';
}
$len = strlen($data);
$l = strlen($key);
$l = strlen($key);
$char = $str = '';
for ($i=0; $i< $len; $i++) {
if ($x == $l) $x = 0;
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{
} else {
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}