composer @Ta | |
2022-01-06 21:23 |
<?php
class Aes
{
public $key = '';
public $iv = '';
public function __construct($config)
{
foreach($config as $k => $v){
$this->$k = $v;
}
}
//加密
public function aesEn($data){
return base64_encode(openssl_encrypt($data, $this->method,$this->key, OPENSSL_RAW_DATA , $this->iv));
}
//解密
public function aesDe($data){
return openssl_decrypt(base64_decode($data), $this->method, $this->key, OPENSSL_RAW_DATA, $this->iv);
}
}
?>
$aes_config = [
'key'=>'abc@123456', //加密key
'iv'=> md5(time(). uniqid(),true), //保证偏移量为16位
'method'=> 'AES-128-CBC' //加密方式 # AES-256-CBC等
];
$obj = new Aes($aes_config);
$res = $obj->aesEn('你好啊');//加密数据
echo $res;
echo '<hr>';
echo $obj->aesDe($res);//解密
阅:1635 | 发表于2022-01-06 21:23 |
心灵鸡汤:
      
®2019-2024 all power by Zlproject3.7
川公网安备 51192202000151号
蜀ICP备2021014921号-2
首页 #top
天合之作 曲在人意