Authored by 周少峰

encrypt function

<?php
/**
* AES, 128 ECB模式加密数据
* 原有的填充方法没用到,否则与java、node不一致,暂时保留
*/
namespace WebPlugin;
... ... @@ -10,20 +11,18 @@ class Encryption {
//密钥
private static $_secretKey = 'yoho9646abcdefgh';
//前面补8位0
private static $_preString = '00000000';
/**
* 加密方法
* @param string $str
* @param string $str 加密字符
* @param string $key 密钥
* @return string
*/
public static function encrypt($str){
$str = self::$_preString.$str;
public static function encrypt($str, $key = ''){
//AES, 128 ECB模式加密数据
$secretKey = self::$_secretKey;
$secretKey = $key ? $key : self::$_secretKey;
$str = trim($str);
$str = self::addPKCS7Padding($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, $secretKey, $str, MCRYPT_MODE_ECB, $iv);
return base64_encode($encrypt_str);
... ... @@ -31,18 +30,18 @@ class Encryption {
/**
* 解密方法
* @param string $str
* @param string $str 解密字符
* @param string $key 密钥
* @return string
*/
public static function decrypt($str){
public static function decrypt($str, $key = ''){
//AES, 128 ECB模式加密数据
$secretKey = self::$_secretKey;
$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, $secretKey, $str, MCRYPT_MODE_ECB, $iv);
$encrypt_str = trim($encrypt_str);
$encrypt_str = self::stripPKSC7Padding($encrypt_str);
$encrypt_str = ltrim($encrypt_str, self::$_preString);
// $encrypt_str = self::stripPKSC7Padding($encrypt_str);
return $encrypt_str;
}
... ...
... ... @@ -14,8 +14,8 @@ define('EXHIBITION_TICKET', 51335912);//展览票skn
define('USE_INTER_FACE_SHUNT', false);//分流开关
#test环境
define('API_URL', 'http://testapi.yoho.cn:28078/');
define('SERVICE_URL', 'http://testservice.yoho.cn:28077/');
define('API_URL', 'http://api-test3.yohops.com:9999/');
define('SERVICE_URL', 'http://service-test3.yohops.com:9999/');
define('YOHOBUY_URL', 'http://www.yohobuy.com/');
define('SERVICE_NOTIFY', 'http://testservice.yoho.cn:28077/');
define('API_OLD', 'http://test2.open.yohobuy.com/');
... ...