1,废话不多说直接上代码,先写一个类
class Crypt {
/**
* [$cipher 加密模式]
* @var [type]
*/
private $cipher = MCRYPT_RIJNDAEL_128;
private $mode = MCRYPT_MODE_CBC;
/**
* [$key 密匙]
* @var string
*/
private $secret_key = 'dc1e8b9ace2d60d3992ecb5e30825253';
function setCipher($cipher=''){
$cipher && $this->cipher = $cipher;
}
function setMode($mode=''){
$mode && $this->mode = $mode;
}
function setSecretKey($secret_key=''){
$secret_key && $this->secret_key = $secret_key;
}
//加密
function encrypt($str,$iv)
{
$size = mcrypt_get_block_size ( MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC );
$str = $this->pkcs5Pad ( $str, $size );
//$data=mcrypt_cbc(MCRYPT_RIJNDAEL_128, $this->secret_key, $str, MC