42 lines
597 B
PHP
42 lines
597 B
PHP
<?php
|
|
|
|
namespace app\util;
|
|
|
|
class Aes {
|
|
|
|
public $key = '';
|
|
|
|
public $iv = '';
|
|
|
|
public $method = '';
|
|
|
|
/**
|
|
|
|
* 构造方法
|
|
|
|
*/
|
|
|
|
public function __construct($key, $iv = '', $method = 'AES-128-ECB')
|
|
{
|
|
$this->method = $method;
|
|
$this->key = $key;
|
|
$this->iv = $iv;
|
|
}
|
|
|
|
// 加密
|
|
|
|
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);
|
|
|
|
}
|
|
}
|