/** * @param $encrypted * @return bool|string */ public function deCode($encrypted) { $encrypted = $this->hexCrypt->DeCode($encrypted); $key = $this->key; $td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, ''); //使用MCRYPT_DES算法,ecb模式 $iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); //$ks = mcrypt_enc_get_key_size($td); @mcrypt_generic_init($td, $key, $iv); //初始处理 $decrypted = mdecrypt_generic($td, $encrypted); //解密 mcrypt_generic_deinit($td); //结束 mcrypt_module_close($td); $y = $this->pkcs5_unpad($decrypted); return $y; }
/** * 解密 * * @param $data * @return string */ public function deCode($data) { $key = $this->getKey(); if ($this->isDecode && $this->hexCrypt) { $data = $this->hexCrypt->DeCode($data); } if ($this->isContainIV) { $iv = substr($data, 0, 16); $data = substr($data, 16); } else { $iv = $this->getIV(); } $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv); return $this->pkcs5Unpad($str); }