/**
* aes
*
*/
class aes{
private $key = "wt@36";
private $iv = "8401948501850295"; //只能是16字节
/**
*
* @param unknown_type $key
* @param string $iv 16 length
*/
function __construct($key,$iv=null){
$this->key = $key;
if (!empty($iv)){
$this->iv = $iv;
}
}
/**
* 加密
* @param string $value
* @return string
*/
function encrypt($value){
return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $value, MCRYPT_MODE_CBC,$this->iv));
}
/*
* AES解密
*/
function decrypt($value){
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, pack("H*",$value),MCRYPT_MODE_CBC, $this->iv);
}
}