This article mainly introduces the AES encryption classes implemented in PHP, the code has the use of methods, the need for friends can refer to the following
Code as follows: <?php class Aesmcrypt { public $iv = null; public $key = null; public $bit = 128; private $cipher; public function __construct ($bit, $key, $iv, $mode) { If empty ($bit) | | empty ($key) | | empty ($IV) | | Mpty ($mode)) return NULL; $this->bit = $bit; $this->key = $key; $this->iv = $iv; $this->mode = $mode; switch ($this->bit) { case: $this->cipher = mcrypt_rijndael_192; break; c ASE 256: $this->cipher = mcrypt_rijndael_256; Break default: $this->cipher = mcrypt_rijndael_128; } switch ($this->mode) { case ' ECB ': $this->mode = MCRYPT_MODE_ECB; break; &N Bsp;case ' CFB ': $this->mode = MCRYPT_MODE_CFB; Break case ' ofb ': $this->mode = MCRYPT_MODE_OFB; Break case ' nofb ': $this->mode = MCRYPT_MODE_NOFB; Break default: $this->mode = MCRYPT_MODE_CBC; }   public function Encrypt ($data) { $data = Base64_encode (Mcrypt_encrypt ($this->ciph Er, $this->key, $data, $this->mode, $this->iv)); return $data; &NBSP} public function decrypt ($data) { $data = Mcrypt_decrypt ($this->cipher, $this->key, base 64_decode ($data), $this->mode, $this->iv); $data = RTrim (RTrim ($data), "x00." x1f "); return $data; &NBSP} } //use method $aes = new Aesmcrypt ($bit = 128, $key = ' abcdef1234567890 ', $iv = ' 0987654321FEDCBA ', $mode = ' CBC '); $c = $aes->encrypt (' haowei.me '); Var_dump ($aes->decrypt ($c));