Encrypt data by key

@param string $data
@param string $key
@return Encrypted
183231
public function encrypt($data, $key) {
      $this->validateData($data);
      $this->validateKey($key);

      $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::CIPHER_METHOD));

      $encrypted = openssl_encrypt($data, self::CIPHER_METHOD, $key, 0, $iv);
      $encoded = base64_encode($encrypted . self::ENCRYPTED_IV_SEPERATOR . $iv);

      return new Encrypted($encoded);
    }
994489
protected function doDecrypt($data, $key, $iv)
    {
        return openssl_decrypt($data, $this->getMethod(), $key, OPENSSL_RAW_DATA, $iv);
    }
200001
public function decrypt($data, $key = null, $iv = null)
    {
        $data = base64_decode($data);

        if (!$iv) {
            $iv = substr($data, 0, static::DEFAULT_RANDOM_BYTE_LENGTH);

            $data = substr($data, static::DEFAULT_RANDOM_BYTE_LENGTH);
        } else {
            if (substr($data, 0, strlen($iv)) === $iv) {
                $data = substr($data, strlen($iv));
            }
        }

        $key = sha1($iv . $key);

        return $this->doDecrypt($data, $key);
    }
1111024
public static byte[] encrypt(byte[] data, byte[] key) {
        checkNotNull(data);
        checkNotNull(key);
        checkArgument(key.length >= 5 && key.length <= 256);
        StreamCipher rc4 = new RC4Engine();
        rc4.init(true, new KeyParameter(key));
        byte[] encrypted = new byte[data.length];
        rc4.processBytes(data, 0, data.length, encrypted, 0);
        return encrypted;
    }
375082
protected static final byte[] encrypt(byte[] data, byte[] key, String cipher) throws Exception {
        SecretKey sKey = constructSecretKey(key, cipher);
        Cipher ci = createCipher(Cipher.ENCRYPT_MODE, key, cipher, sKey);
        return ci.doFinal(data);
    }
57727
public function decrypt($data, $key) {
        if ($data === '') {
            return $data;
        }

        $cipher = $this->createCipher($key);

        $decrypted = mdecrypt_generic($cipher, $data);

        $this->clearCipher($cipher);

        return rtrim($decrypted, "\0");
    }
1060041
public function encrypt($data)
    {
        return base64_encode(openssl_encrypt($data, $this->cipher, $this->key, 0, $this->iv).'&&'.bin2hex($this->iv));
    }
998086
public static function encrypt($data, $key = null)
    {
        is_null($key) && $key = Config::get('auth_key');
        return self::cry(serialize($data), 1, $key);
    }
1081834
public function crypt(string $data) {
        $keyHash = md5(Config::getConfig()->encrypt->key);
        $key = substr($keyHash, 0, mcrypt_get_key_size(self::$cipher, self::$mode));
        $iv = substr($keyHash, 0, mcrypt_get_block_size(self::$cipher, self::$mode));
        return base64_encode(mcrypt_encrypt(self::$cipher, $key, $data, self::$mode, $iv));
    }
1305805
public function aes128EcbEncrypt($key, $data, $iv)
    {
        if (16 !== strlen($key)) {
            $key = hash('MD5', $key, TRUE);
        }
        if (16 !== strlen($iv)) {
            $iv = hash('MD5', $iv, TRUE);
        }
        $padding = 16 - (strlen($data) % 16);
        $data    .= str_repeat(chr($padding), $padding);
        $result  = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB, $iv);

        return $result;
    }
404470
public function encrypt($data, Key $key)
	{
		// Validate key.
		if ($key->getType() !== 'sodium')
		{
			throw new InvalidKeyTypeException('sodium', $key->getType());
		}

		if (!$this->nonce)
		{
			throw new \RuntimeException('Missing nonce to decrypt data');
		}

		return Compat::crypto_box(
			$data,
			$this->nonce,
			Compat::crypto_box_keypair_from_secretkey_and_publickey($key->getPrivate(), $key->getPublic())
		);
	}
363314
public static function decrypt($data = '', $key = ''): string
    {
        $key = md5(empty($key) ? \Yii::$app->getRequest()->cookieValidationKey : $key);
        $data = str_replace(['-', '_'], ['+', '/'], $data);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }
        $data = base64_decode($data);
        $expire = substr($data, 0, 10);
        $data = substr($data, 10);
        
        if ($expire > 0 && $expire < time()) {
            return '';
        }
        $x = 0;
        $len = strlen($data);
        $l = strlen($key);
        $char = $str = '';
        
        for ($i = 0; $i < $len; $i++) {
            if ($x == $l) {
                $x = 0;
            }
            $char .= substr($key, $x, 1);
            $x++;
        }
        
        for ($i = 0; $i < $len; $i++) {
            if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
                $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
            } else {
                $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
            }
        }
        
        return base64_decode($str);
    }
1255056
public function encryptByPrivateKey_data($data, $privatekey = '')
	{
		$RSACrypt = new RSACrypt();

		if ($privatekey != "") {
			$RSACrypt->privkey = $privatekey;
		}
		$crypt_res = "";
		for ($i = 0; $i < ((strlen($data) - strlen($data) % 117) / 117 + 1); $i++) {
			$crypt_res = $crypt_res . ($RSACrypt->encryptByPrivateKey(mb_strcut($data, $i * 117, 117, 'utf-8')));
		}
		return $crypt_res;
	}
1206431
public static function Encrypt ($data, $key, $options = []) {
		$options = static::_AdjustOptions($options);
		return openssl_encrypt($data, $options['method'], $key, $options['openssl_options'], $options['iv']);
	}
1284213
public function decryptByPrivateKey_data($data, $privatekey = '')
	{
		$RSACrypt = new RSACrypt();

		if ($privatekey != "") {  // if null use default
			$RSACrypt->privkey = $privatekey;
		}
		$decrypt_res = "";
		$datas = explode('@', $data);
		foreach ($datas as $value) {
			$decrypt_res = $decrypt_res . $RSACrypt->decryptByPrivateKey($value);
		}
		return $decrypt_res;
	}
983290
public function decrypt($data, Key $key)
	{
		// Validate key.
		if ($key->type != 'simple')
		{
			throw new \InvalidArgumentException('Invalid key of type: ' . $key->type . '.  Expected simple.');
		}

		$decrypted = '';
		$tmp = $key->public;

		// Convert the HEX input into an array of integers and get the number of characters.
		$chars = $this->_hexToIntArray($data);
		$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++)
		{
			$decrypted .= chr($chars[$i] ^ ord($tmp[$i]));
		}

		return $decrypted;
	}
700454
public static function insert($key, $data)
    {
        if (self::$configurator instanceof ConfiguratorClass) {
            return self::$configurator->insert($key, $data);
        } else {
            return null;
        }
    }