Authored by 周少峰

encreyption less 8

@@ -10,12 +10,16 @@ class Encryption { @@ -10,12 +10,16 @@ class Encryption {
10 //密钥 10 //密钥
11 private static $_secrect_key = 'yoho9646abcdefgh'; 11 private static $_secrect_key = 'yoho9646abcdefgh';
12 12
  13 + //前面补8位0
  14 + private static $_preString = '00000000';
  15 +
13 /** 16 /**
14 * 加密方法 17 * 加密方法
15 * @param string $str 18 * @param string $str
16 * @return string 19 * @return string
17 */ 20 */
18 public static function encrypt($str){ 21 public static function encrypt($str){
  22 + $str = self::$_preString.$str;
19 //AES, 128 ECB模式加密数据 23 //AES, 128 ECB模式加密数据
20 $screct_key = self::$_secrect_key; 24 $screct_key = self::$_secrect_key;
21 $str = trim($str); 25 $str = trim($str);
@@ -38,6 +42,7 @@ class Encryption { @@ -38,6 +42,7 @@ class Encryption {
38 $encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_ECB, $iv); 42 $encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_ECB, $iv);
39 $encrypt_str = trim($encrypt_str); 43 $encrypt_str = trim($encrypt_str);
40 $encrypt_str = self::stripPKSC7Padding($encrypt_str); 44 $encrypt_str = self::stripPKSC7Padding($encrypt_str);
  45 + $encrypt_str = ltrim($encrypt_str, self::$_preString);
41 return $encrypt_str; 46 return $encrypt_str;
42 47
43 } 48 }