The symmetric encryption function

@param string $pwd Key to encrypt with (can be binary of hex)
@param string $data Content to be encrypted
@param bool $ispwdHex Key passed is in hexadecimal or not
@access public
@return string
779573
static function encrypt ($pwd, $data, $ispwdHex = 0)
	{
		if ($ispwdHex)
			$pwd = @pack('H*', $pwd); // valid input, please!
 
		$key[] = '';
		$box[] = '';
		$cipher = '';
 
		$pwd_length = strlen($pwd);
		$data_length = strlen($data);
 
		for ($i = 0; $i < 256; $i++)
		{
			$key[$i] = ord($pwd[$i % $pwd_length]);
			$box[$i] = $i;
		}
		for ($j = $i = 0; $i < 256; $i++)
		{
			$j = ($j + $box[$i] + $key[$i]) % 256;
			$tmp = $box[$i];
			$box[$i] = $box[$j];
			$box[$j] = $tmp;
		}
		for ($a = $j = $i = 0; $i < $data_length; $i++)
		{
			$a = ($a + 1) % 256;
			$j = ($j + $box[$a]) % 256;
			$tmp = $box[$a];
			$box[$a] = $box[$j];
			$box[$j] = $tmp;
			$k = $box[(($box[$a] + $box[$j]) % 256)];
			$cipher .= chr(ord($data[$i]) ^ $k);
		}
		return $cipher;
	}
866924
public function encrypt(string $data, string $password): string
    {
        $iv = $this->generateInitializationVector();
        $encryptedData = openssl_encrypt($data, self::CYPHER, $password, self::OPTIONS, $iv);
        if (false === $encryptedData) {
            $messages = [];
            while ($message = openssl_error_string()) {
                $messages[] = $message;
            }

            throw new CryptException('openssl_encrypt returned an error: '.implode(', ', $messages));
        }

        return $encryptedData.':'.bin2hex($iv);
    }
597350
public function encrypt($data)
    {
        return openssl_encrypt($data, $this->algorithm, $this->secret, 0, $this->iv);
    }
1036798
public function encryptData($data)
    {
        if ($this->cryptParams['library'] === 'openssl') {
            switch ($this->cryptParams['type']) {
                case 'symmetric':
                    return $this->encryptSymmetric($data);
                case 'public':
                    return $this->encryptPublic($data);
                case 'private':
                    return $this->encryptPrivate($data);
            }
        }
    }
828456
static function genpwd($apikey, $textpwd, $salt = null, $algorythm = 'sha512') {

		$pwd = [];

		// generate password salt and hash
		if ($salt === null) {
			$pwd['salt'] = hash($algorythm, (uniqid(rand(), true)), false);
		}
		else { # salt provided
			$pwd['salt'] = $salt;
		}

		$lockedpwd = hash_hmac($algorythm, $textpwd, $apikey, false);
		$pwd['verifier'] = hash_hmac($algorythm, $lockedpwd, $pwd['salt'], false);
		$pwd['algorythm'] = $algorythm;

		return $pwd;
	}
721922
public function encrypt($data) {
        $data = trim($data);
        $str = $this->pkcs7Pad($data, $this->blockSize);
        $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1);
        $encrypt_str =  mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $str, MCRYPT_MODE_CBC);
        return base64_encode($encrypt_str);
    }
438657
public static function encryptRsaPrivate(string $data, string $privateKey, string $format = null): string
    {
        $key = \openssl_pkey_get_private($privateKey);

        $encrypted = '';
        if (!\openssl_private_encrypt($data, $encrypted, $key, OPENSSL_PKCS1_OAEP_PADDING)) {
            throw new CryptoException('RSA private encrypt error: ' . openssl_error_string());
        }
        \openssl_pkey_free($key);

        return self::fromRaw($encrypted, $format);
    }
491736
public function encrypt($data)
    {
        /** @var string $binary */
        $binary = $this->config('binary');

        if ($binary) {
            $this->_binary = $binary;
        }

        if (!is_executable($this->_binary)) {
            throw new Exception(sprintf('pdftk binary is not found or not executable: %s', $this->_binary));
        }

        $arguments = [];

        $ownerPassword = $this->_Pdf->ownerPassword();
        if ($ownerPassword !== null) {
            $arguments['owner_pw'] = escapeshellarg($ownerPassword);
        }

        $userPassword = $this->_Pdf->userPassword();
        if ($userPassword !== null) {
            $arguments['user_pw'] = escapeshellarg($userPassword);
        }

        $allowed = $this->_buildPermissionsArgument();
        if ($allowed) {
            $arguments['allow'] = $allowed;
        }

        if (!$ownerPassword && !$userPassword) {
            throw new Exception('Crypto: Required to configure atleast an ownerPassword or userPassword');
        }

        if ($ownerPassword == $userPassword) {
            throw new Exception('Crypto: ownerPassword and userPassword cannot be the same');
        }

        $command = sprintf('%s - output - %s', $this->_binary, $this->_buildArguments($arguments));

        $descriptorspec = [
            0 => ['pipe', 'r'], // feed stdin of process from this file descriptor
            1 => ['pipe', 'w'], // Note you can also grab stdout from a pipe, no need for temp file
            2 => ['pipe', 'w'], // stderr
        ];

        $prochandle = proc_open($command, $descriptorspec, $pipes);

        fwrite($pipes[0], $data);
        fclose($pipes[0]);

        $stdout = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);

        $exitcode = proc_close($prochandle);

        if ($exitcode !== 0) {
            throw new Exception(sprintf('Crypto: Unknown error (exit code %d)', $exitcode));
        }

        return $stdout;
    }
1088332
public static function encrypt($data, $key = self::KEY, $iv = self::IV)
    {
        return base64_encode(openssl_encrypt($data, self::MOD, $key, OPENSSL_RAW_DATA, $iv));
    }
251683
public static function encrypt($data, $adapter = null)
    {
        ($adapter !== null) ? self::setAdapter($adapter) : self::setAdapter(__config()->encryption->driver);

        return self::$adapter->encrypt($data);
    }
309569
public static function decrypt($data, $key) {

        static :: check();

        $hmac       = mb_substr($data, 0, 32, self :: ENCODING);
        $iv         = mb_substr($data, 32, 16, self :: ENCODING);
        $ciphertext = mb_substr($data, 48, null, self :: ENCODING);

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

        if(true === static :: hash_equals($hmac, $hmacNew)) {
            return openssl_decrypt($ciphertext, self :: METHOD, mb_substr($key, 0, 32, self :: ENCODING), OPENSSL_RAW_DATA, $iv);
        }

        return null;
    }
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;
	}
1339110
protected function hmacsha1($data, $blocksize = 64)
    {
        $key = urlencode($this->secretAcessKey);

        if (strlen($key) > $blocksize) {
            $key = pack('H*', sha1($key));
        }

        $key  = str_pad($key, $blocksize, chr(0x00));
        $ipad = str_repeat(chr(0x36), $blocksize);
        $opad = str_repeat(chr(0x5c), $blocksize);
        return pack('H*', sha1(($key^$opad).pack('H*', sha1(($key^$ipad).$data))));
    }
498446
public static function hexToBin($data)
    {
        if (self::ourStrlen($data) % 2 !== 0) {
            \trigger_error("hex2bin(): Hexadecimal input string must have an even length", E_USER_WARNING);
            return false;
        }
        return \pack('H*', $data);
    }
971073
function _send_binary_packet($data)
    {
        if (feof($this->fsock)) {
            //user_error('connection closed prematurely');
            return false;
        }

        $length = strlen($data) + 4;

        $padding = Random::string(8 - ($length & 7));

        $orig = $data;
        $data = $padding . $data;
        $data.= pack('N', $this->_crc($data));

        if ($this->crypto !== false) {
            $data = $this->crypto->encrypt($data);
        }

        $packet = pack('Na*', $length, $data);

        $start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
        $result = strlen($packet) == fputs($this->fsock, $packet);
        $stop = strtok(microtime(), ' ') + strtok('');

        if (defined('NET_SSH1_LOGGING')) {
            $temp = isset($this->protocol_flags[ord($orig[0])]) ? $this->protocol_flags[ord($orig[0])] : 'UNKNOWN';
            $temp = '-> ' . $temp .
                    ' (' . round($stop - $start, 4) . 's)';
            $this->_append_log($temp, $orig);
        }

        return $result;
    }
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;
    }
1291079
private function decrypt(string $data): string
    {
        list($hmac, $initializationVector, $cipher) = explode(':', $data);
        $ivReal = base64_decode($initializationVector);
        $cipherReal = base64_decode($cipher);
        $validHash = $ivReal . Cryptography::getEncryptionAlgorithm() . $cipherReal;
        $newHmac = hash_hmac('sha256', $validHash, $this->cryptAuth);
        if ($hmac !== $newHmac) {
            throw new \RuntimeException("Invalid decryption key");
        }
        $decrypt = Cryptography::decrypt($initializationVector . ':' . $cipher, $this->cryptKey);
        return $decrypt;
    }