1
This commit is contained in:
@@ -127,6 +127,47 @@ class Welcome extends CI_Controller {
|
||||
var_dump($response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function encrypt($data, $key) {
|
||||
$key = base64_decode($key);
|
||||
if (strlen($key) < 16) {
|
||||
$key = str_pad($key, 16, "\0");
|
||||
} elseif (strlen($key) > 16) {
|
||||
$key = substr($key, 0, 16);
|
||||
}
|
||||
$iv = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; // ECB模式不需要IV,但PHP的openssl_encrypt函数需要
|
||||
return openssl_encrypt($data, 'AES-128-ECB', $key, OPENSSL_RAW_DATA, $iv);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将加密后的二进制数据转换成十六进制字符串
|
||||
* @param string $binaryData 加密后的二进制数据
|
||||
* @return string 十六进制字符串
|
||||
*/
|
||||
public static function parseBinary2HexStr($binaryData) {
|
||||
return bin2hex($binaryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密数据并返回十六进制字符串
|
||||
* @param mixed $obj 待加密的数据
|
||||
* @param string $key 密钥
|
||||
* @return string 加密后的十六进制字符串
|
||||
*/
|
||||
public static function encryptData($obj, $key) {
|
||||
$content = is_string($obj) ? $obj : serialize($obj);
|
||||
$encrypted = self::encrypt($content, $key);
|
||||
return self::parseBinary2HexStr($encrypted);
|
||||
}
|
||||
|
||||
public function tt()
|
||||
{
|
||||
$key = "B066+uPhhihfn0CLrU5Cpw==";
|
||||
$data = "0534_1716970275384";
|
||||
$encryptedData = $this->encryptData($data, $key);
|
||||
echo "加密内容:" . $encryptedData . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ class Welcome extends Wx
|
||||
throw new Hd_exception("参数错误", 400);
|
||||
}
|
||||
$this->data['skey'] = $this->skey;
|
||||
|
||||
if($this->skey == 'dG9waWNfaWQ9Ng'){
|
||||
debug_log("params:". json_encode($this->input->get()), 'auto.txt');
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
|
||||
Reference in New Issue
Block a user