|
@@ -42,4 +42,45 @@ class ZskkDefaultApiController extends ZskkDefaultController {
|
|
|
//返回数据
|
|
|
return $output;
|
|
|
}
|
|
|
+
|
|
|
+ public function getDecryptData($data)
|
|
|
+ {
|
|
|
+ $key = 'zLxapoeqWYpoeqWY';
|
|
|
+ $info = $this->decrypt($key,$data);
|
|
|
+ if(empty($info))
|
|
|
+ {
|
|
|
+ return '数据解析失败';
|
|
|
+ }else{
|
|
|
+ $arr = json_decode(base64_decode($info),true);
|
|
|
+ if(empty($arr))
|
|
|
+ {
|
|
|
+ return '数据解析失败,失败原因:数据加密前未进行base64转换';
|
|
|
+ }
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function encrypt($key, $str)
|
|
|
+ {
|
|
|
+ if($str) {
|
|
|
+ $iv = str_repeat("\0", openssl_cipher_iv_length('SM4-CBC'));
|
|
|
+ $ciphertext = openssl_encrypt($str, 'SM4-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
|
|
+ return base64_encode($ciphertext);
|
|
|
+ }
|
|
|
+ return $str;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 国密4解密
|
|
|
+ * str 解密字符串
|
|
|
+ */
|
|
|
+ public static function decrypt($key, $str)
|
|
|
+ {
|
|
|
+ if($str) {
|
|
|
+ $iv = str_repeat("\0", openssl_cipher_iv_length('SM4-CBC'));
|
|
|
+ return openssl_decrypt(base64_decode($str), 'SM4-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
|
|
+ }
|
|
|
+ return $str;
|
|
|
+ }
|
|
|
}
|