<?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);
    }
}
