Encrypts a text

@param string $text
@param string $key

@return string
967663
public function encrypt($text, $key)
    {
        $ivSize = mcrypt_enc_get_block_size($this->_mcrypt);
        $encryptKey = md5($key, true);

        /** @noinspection CryptographicallySecureRandomnessInspection */
        $iv = mcrypt_create_iv($ivSize, MCRYPT_DEV_URANDOM);

        mcrypt_generic_init($this->_mcrypt, $encryptKey, $iv);

        return $iv . mcrypt_generic($this->_mcrypt, pack('N', strlen($text) + 16) . $text . md5($text, true));
    }
1317703
public function decrypt($text): string
    {
        $length = strlen($text);
        $plain = '';
        for ($iteration = 0; $iteration < $length; $iteration += 8) {
            $aBlock = $this->asc2int(substr($text, $iteration, 4));
            $bBlock = $this->asc2int(substr($text, $iteration + 4, 4));
            list($aBlock, $bBlock) = $this->bfDecrypt($aBlock, $bBlock);
            $plain .= $this->int2asc($aBlock) . $this->int2asc($bBlock);
        }
        return $plain;
    }
592870
public function encrypt($data, Key $key)
	{
		// Validate key.
		if ($key->type != 'simple')
		{
			throw new \InvalidArgumentException('Invalid key of type: ' . $key->type . '.  Expected simple.');
		}

		$encrypted = '';
		$tmp = $key->private;

		// Split up the input into a character array and get the number of characters.
		$chars = preg_split('//', $data, -1, PREG_SPLIT_NO_EMPTY);
		$charCount = count($chars);

		// Repeat the key as many times as necessary to ensure that the key is at least as long as the input.
		for ($i = 0; $i < $charCount; $i = strlen($tmp))
		{
			$tmp = $tmp . $tmp;
		}

		// Get the XOR values between the ASCII values of the input and key characters for all input offsets.
		for ($i = 0; $i < $charCount; $i++)
		{
			$encrypted .= $this->_intToHex(ord($tmp[$i]) ^ ord($chars[$i]));
		}

		return $encrypted;
	}
885405
function _crypt($text, $mode)
    {
        if ($this->changed) {
            $this->_setup();
            $this->changed = false;
        }

        $stream = &$this->stream[$mode];
        if ($this->continuousBuffer) {
            $i = &$stream[0];
            $j = &$stream[1];
            $keyStream = &$stream[2];
        } else {
            $i = $stream[0];
            $j = $stream[1];
            $keyStream = $stream[2];
        }

        $len = strlen($text);
        for ($k = 0; $k < $len; ++$k) {
            $i = ($i + 1) & 255;
            $ksi = $keyStream[$i];
            $j = ($j + $ksi) & 255;
            $ksj = $keyStream[$j];

            $keyStream[$i] = $ksj;
            $keyStream[$j] = $ksi;
            $text[$k] = $text[$k] ^ chr($keyStream[($ksj + $ksi) & 255]);
        }

        return $text;
    }
1132957
public static function encrypt($string, $key, $cipher, $mode = MCRYPT_MODE_CBC) {
        list($key, $iv) = static::vector($key, $cipher, $mode);

        return mcrypt_encrypt($cipher, $key, $string, $mode, $iv);
    }
998086
public static function encrypt($data, $key = null)
    {
        is_null($key) && $key = Config::get('auth_key');
        return self::cry(serialize($data), 1, $key);
    }
548624
public static function rijndael($string, $key, $operation = self::ENCRYPT) {
        if ($operation === static::ENCRYPT) {
            return static::encrypt($string, $key, static::RIJNDAEL);
        } else {
            return static::decrypt($string, $key, static::RIJNDAEL);
        }
    }
1125172
public function encrypt($string, $key)
    {
        $string = "ox{$string}id";

        $key = $this->_formKey($key, $string);

        $string = $string ^ $key;
        $string = base64_encode($string);
        $string = str_replace("=", "!", $string);

        return "ox_$string";
    }
133394
public static function encrypt($data, $key) {

        static :: check();
        
        $iv = static :: random_bytes(16);
        
        //Encryption
        $ciphertext = openssl_encrypt($data, self :: METHOD, mb_substr($key, 0, 32, self :: ENCODING), OPENSSL_RAW_DATA, $iv);

        //Authentication
        $hmac = hash_hmac(self :: ALGORITHM, $iv . $ciphertext, mb_substr($key, 32, null, self :: ENCODING), true);

        return $hmac . $iv . $ciphertext;
    }
187056
private function encrypt($text) {
		if(!$this->key) {
			$this->key = base64_decode($this->manager->app->aeskey . '=');
		}

		//获得16位随机字符串，填充到明文之前
		$random = $this->manager->generateRandomString(16);
		$text = $random . pack("N", strlen($text)) . $text . $this->manager->app->appid;

		//网络字节序
		$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
		$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
		$iv = substr($this->key, 0, 16);

		//使用自定义的填充方式对明文进行补位填充
		$text = $this->encode($text);
		mcrypt_generic_init($module, $this->key, $iv);

		//加密
		$encrypted = mcrypt_generic($module, $text);
		mcrypt_generic_deinit($module);
		mcrypt_module_close($module);

		//使用BASE64对加密后的字符串进行编码
		return base64_encode($encrypted);
	}
216092
function encrypt($plaintext)
    {
        if ($this->engine == self::ENGINE_OPENSSL) {
            $temp = $this->key;
            $this->key = $this->orig_key;
            $result = parent::encrypt($plaintext);
            $this->key = $temp;
            return $result;
        }

        return parent::encrypt($plaintext);
    }
744242
public static function encrypt($message, $key, $encode = false)
    {
        list($encKey, $authKey) = self::splitKeys($key);

        // Pass to UnsafeCrypto::encrypt
        $ciphertext = parent::encrypt($message, $encKey);

        // Calculate a MAC of the IV and ciphertext
        $mac = hash_hmac(self::HASH_ALGO, $ciphertext, $authKey, true);

        if ($encode) {
            return base64_encode($mac.$ciphertext);
        }
        // Prepend MAC to the ciphertext and return to caller
        return $mac.$ciphertext;
    }
712711
function decode($text)
    {
        $pad = ord(substr($text, -1));
        if ($pad < 1 || $pad > PKCS7Encoder::$blockSize) {
            $pad = 0;
        }
        return substr($text, 0, strlen($text) - $pad);
    }
1090226
function encrypt($text, $keys, $sign_key = null)
    {
        try {
            foreach ($keys as $key) {
                $this->gpg->addEncryptKey($key->reference);
            }

            if ($sign_key) {
                $this->gpg->addSignKey($sign_key->reference, $sign_key->password);

                $res     = $this->gpg->encryptAndSign($text, true);
                $sigInfo = $this->gpg->getLastSignatureInfo();

                $this->last_sig_algorithm = $sigInfo->getHashAlgorithmName();

                return $res;
            }

            return $this->gpg->encrypt($text, true);
        }
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
1090795
public function encrypt($string, $key = null, $iv = null)
    {
        $key = $key ?: $this->getKey();
        $iv = $iv ?: $this->getIv();

        return $this->cipher->encrypt($string, $key, $iv);
    }
171341
public function encrypt($input, $key = '')
    {
        if (empty($input)) return $input;
        if (empty($key)) $key = md5($this->key);
        $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
        $ikey ="-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
        $nh1 = rand(0,64);
        $nh2 = rand(0,64);
        $nh3 = rand(0,64);
        $ch1 = $chars{$nh1};
        $ch2 = $chars{$nh2};
        $ch3 = $chars{$nh3};
        $nhnum = $nh1 + $nh2 + $nh3;
        $knum = 0;$i = 0;
        while(isset($key{$i})) $knum +=ord($key{$i++});
        $mdKey = substr(md5(md5(md5($key.$ch1).$ch2.$ikey).$ch3),$nhnum%8,$knum%8 + 16);
        $input = base64_encode(time().'_'.$input);
        $input = str_replace(array('+','/','='),array('-','_','.'),$input);
        $tmp = '';
        $j=0;$k = 0;
        $tlen = strlen($input);
        $klen = strlen($mdKey);
        for ($i=0; $i<$tlen; $i++) {
            $k = $k == $klen ? 0 : $k;
            $j = ($nhnum+strpos($chars,$input{$i})+ord($mdKey{$k++}))%64;
            $tmp .= $chars{$j};
        }
        $tmplen = strlen($tmp);
        $tmp = substr_replace($tmp,$ch3,$nh2 % ++$tmplen,0);
        $tmp = substr_replace($tmp,$ch2,$nh1 % ++$tmplen,0);
        $tmp = substr_replace($tmp,$ch1,$knum % ++$tmplen,0);
        return $tmp;
    }
1074200
protected function encrypt($string)
    {
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->cipherMode), MCRYPT_RAND);

        return mcrypt_encrypt($this->cipher, $this->secretKey, $string, $this->cipherMode, $iv);
    }