AES-ECB-128 pkcs5填充加解密 class AesEncryptService { /** * @desc AES-128-ECB加密 * @param $str * @param $encryptKey * @return string */ public static function AesEncrypt($str, $encryptKey) { if (version_compare(PHP_VERSION, '7.1.0', '<')) { $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $input = self::addPKCS5Padding($str, $size); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $encryptKey, $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td);