<?php
namespace lib;

/**
* AES128加解密类
* @author dy
*
*/
class Aes
{
//密钥
private $_secrect_key;

public function __construct()
{
$this->_secrect_key = md5(SYS_KEY);
}

/**
* 加密方法
* @param string $string
* @return string
*/
public function encrypt($string)
{
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this->_secrect_key), $string, MCRYPT_MODE_CBC, md5(md5($this->_secrect_key))));
}

/**
* 解密方法
* @param string $string
* @return string
*/
public function decrypt($string)
{
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($this->_secrect_key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($this->_secrect_key))), "12");
}
}
