/** * Run the mcrypt decryption routine for the value. * * @param string $value * @param string $iv * @return string * * @throws \Illuminate\Contracts\Encryption\DecryptException */ protected function mcryptDecrypt($value, $iv) { try { return mcrypt_decrypt($this->cipher, $this->key, $value, MCRYPT_MODE_CBC, $iv); } catch (Exception $e) { throw new DecryptException($e->getMessage()); } }//run function to decryption routine // this is a wrap about the mcrypt_decrypt /** * Add PKCS7 padding to a given value. * * @param string $value * @return string */ protected function addPadding($value) { $pad = $this->block - (strlen($value) % $this->block);// this is a number return $value.str_repeat(chr($pad), $pad);// get this wale repeat this }// bad pad function /** * Remove the padding from the given value. * * @param string $value * @return string */ protected function stripPadding($value) { $pad = ord($value[($len = strlen($value)) - 1]); return $this->paddingIsValid($pad, $value) ? substr($value, 0, $len - $pad) : $value; }// remove the padding from the given value. // check this value /** * Determine if the given padding for a value is valid. * * @param string $pad * @param string $value * @return bool */ protected function paddingIsValid($pad, $value) { $beforePad = strlen($value) - $pad; return substr($value, $beforePad) == str_repeat(substr($value, -1), $pad); }// check pad valid /** * Get the IV size for the cipher. * * @return int */ protected function getIvSize() { return mcrypt_get_iv_size($this->cipher, MCRYPT_MODE_CBC); }// get the iv size /** * Get the random data source available for the OS. * * @return int */ protected function getRandomizer()// get the random { if (defined(‘MCRYPT_DEV_URANDOM‘)) { return MCRYPT_DEV_URANDOM; } if (defined(‘MCRYPT_DEV_RANDOM‘)) { return MCRYPT_DEV_RANDOM; } mt_srand(); return MCRYPT_RAND; } }
时间: 2024-10-13 07:06:21