|
|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
<?php
|
|
|
|
|
namespace App\Lib;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
class HSM
|
|
|
|
|
{
|
|
|
|
|
protected static $baseurl="http://223.70.139.221:2018";
|
|
|
|
|
@ -9,8 +11,8 @@ class HSM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//加密
|
|
|
|
|
public static function HsmEncrypt($str){
|
|
|
|
|
$str = bin2hex($str);
|
|
|
|
|
public static function HsmEncrypt($or_str){
|
|
|
|
|
$str = bin2hex($or_str);
|
|
|
|
|
$url= self::$baseurl."/api/hsm/sym/symEncryptInternalForKEK";
|
|
|
|
|
$data=[
|
|
|
|
|
"keyIndex"=>self::$keyIndex,
|
|
|
|
|
@ -19,11 +21,12 @@ class HSM
|
|
|
|
|
"plainData"=>$str
|
|
|
|
|
];
|
|
|
|
|
$data=json_encode($data);
|
|
|
|
|
$encryptStr=self::post($url,$data);
|
|
|
|
|
$encryptStr=self::post($url,$data,$or_str);
|
|
|
|
|
|
|
|
|
|
$r_data=json_decode($encryptStr, true);
|
|
|
|
|
// dd($r_data);
|
|
|
|
|
if($r_data['status']==0){
|
|
|
|
|
return $r_data['body']['cipherData'];
|
|
|
|
|
return ['status'=>true,'data'=>$r_data['body']['cipherData']];
|
|
|
|
|
}else{
|
|
|
|
|
return ['status'=>false];
|
|
|
|
|
}
|
|
|
|
|
@ -39,14 +42,15 @@ class HSM
|
|
|
|
|
];
|
|
|
|
|
$data=json_encode($data);
|
|
|
|
|
$encryptStr=self::post($url,$data);
|
|
|
|
|
|
|
|
|
|
$r_data=json_decode($encryptStr, true);
|
|
|
|
|
if($r_data['status']==0){
|
|
|
|
|
return hex2bin($r_data['body']['plain']);
|
|
|
|
|
return ['status'=>true,'data'=>hex2bin($r_data['body']['plain'])];
|
|
|
|
|
}else{
|
|
|
|
|
return ['status'=>false];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public function post($url, $data_string)
|
|
|
|
|
public function post($url, $data_string,$or_str='')
|
|
|
|
|
{
|
|
|
|
|
$curl = curl_init();
|
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
|
|
|
@ -61,6 +65,22 @@ class HSM
|
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
|
|
|
|
|
$r = curl_exec($curl);
|
|
|
|
|
curl_close($curl);
|
|
|
|
|
|
|
|
|
|
date_default_timezone_set('PRC');
|
|
|
|
|
$table_name='zz_request_log_' . date('ym');
|
|
|
|
|
$formatted_date= date("Y-m-d H:i:s");
|
|
|
|
|
DB::table($table_name)->insert([
|
|
|
|
|
'request_ip'=>'',
|
|
|
|
|
'response_data'=>json_encode($r, JSON_UNESCAPED_UNICODE),
|
|
|
|
|
'header_data'=>'',
|
|
|
|
|
'post_data'=>$or_str.'/'.$data_string,
|
|
|
|
|
'get_data'=>'',
|
|
|
|
|
'request_url'=>$url,
|
|
|
|
|
'create_time' => $formatted_date,
|
|
|
|
|
'update_time' => $formatted_date
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|