/** * 加密 * * @param $data * @return array */ public function enCode($data) { $key = $this->getKey(); $iv = $this->getIV(); $s = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $this->pkcs5Pad($data), MCRYPT_MODE_CBC, $iv); if ($this->isContainIV) { $s = $iv . $s; } if ($this->isDecode && $this->hexCrypt) { return $this->hexCrypt->EnCode($s); } return $s; }
/** * @param $input * @return string */ public function enCode($input) { $size = mcrypt_get_block_size(MCRYPT_DES, MCRYPT_MODE_ECB); $input = $this->pkcs5_pad($input, $size); $key = $this->key; $td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, ''); $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); @mcrypt_generic_init($td, $key, $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = $this->hexCrypt->EnCode($data); return $data; }