You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
652 B
30 lines
652 B
<?php
|
|
namespace app\common\lib;
|
|
|
|
class Aes{
|
|
|
|
private $key = 'iloveutel';
|
|
private $iv = '1234567890123456';
|
|
private $method = 'AES-128-CBC';
|
|
|
|
/**
|
|
* 構造方法
|
|
*/
|
|
public function __construct($config){
|
|
foreach($config as $k=>$v){
|
|
|
|
$this->$k = $v;
|
|
}
|
|
}
|
|
|
|
// 加密
|
|
public function encrypt($data){
|
|
return base64_encode(openssl_encrypt($data, $this->method,$this->key, OPENSSL_RAW_DATA , $this->iv));
|
|
}
|
|
|
|
//解密
|
|
public function descrypt($data){
|
|
return openssl_decrypt(base64_decode($data), $this->method, $this->key, OPENSSL_RAW_DATA, $this->iv);
|
|
}
|
|
}
|