Authored by 周少峰

modify encryption

... ... @@ -9,7 +9,7 @@ namespace Plugin;
class Encryption {
//密钥
private static $_secrect_key = 'yoho9646abcdefgh';
private static $_secretKey = 'yoho9646abcdefgh';
/**
* 加密方法
... ... @@ -20,11 +20,11 @@ class Encryption {
public static function encrypt($str, $key = ''){
//AES, 128 ECB模式加密数据
$screct_key = $key ? $key : self::$_secrect_key;
$secretKey = $key ? $key : self::$_secretKey;
$str = trim($str);
// $str = self::addPKCS7Padding($str);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND);
$encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_ECB, $iv);
$encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secretKey, $str, MCRYPT_MODE_ECB, $iv);
return base64_encode($encrypt_str);
}
... ... @@ -36,10 +36,10 @@ class Encryption {
*/
public static function decrypt($str, $key = ''){
//AES, 128 ECB模式加密数据
$screct_key = $key ? $key : self::$_secrect_key;
$secretKey = $key ? $key : self::$_secretKey;
$str = base64_decode($str);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND);
$encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_ECB, $iv);
$encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $secretKey, $str, MCRYPT_MODE_ECB, $iv);
$encrypt_str = trim($encrypt_str);
// $encrypt_str = self::stripPKSC7Padding($encrypt_str);
return $encrypt_str;
... ...