Encrypt the data (depends on the value of class members)
@param string $strData

@return mixed|string
@throws Q\Exception\Cryptography
764186
public function encrypt($strData)
    {
        $strEncryptedData = openssl_encrypt($strData, $this->strCipher, $this->strKey, 0, $this->strIv);

        if ($this->strIvHashKey) {
            // User has asked to include the IV with the encrypted string so that we do not have to store the IV somewhere else.
            /**
             * Based on http://pastebin.com/sN6buivY
             * True will append the initialization vector and a hash value to the end of the cryptography so that:
             * a) The crypto can be unencrypted without having to save the IV
             * b) The crypto can be tested for tampering using the hash.
             *
             * Will increase the size of the resulting value by the size of the IV + about 50%. The other option is to serialize the class or in
             * some other way save the IV and restore it later.
             */
            $strEncryptedData .= ':' . bin2hex($this->strIv);
            $strEncryptedData .= ':' . hash_hmac('sha256', $strEncryptedData, $this->strIvHashKey);
        }

        if ($this->blnBase64) {
            $strEncryptedData = QString::base64UrlSafeEncode($strEncryptedData);
        }

        return $strEncryptedData;
    }
1163898
public function encrypt($data)
	{
		if (!$this->encEnabled) return $data; // no encryption
		switch ($this->encMethod) {
			case 'SIMPLE':
				return $this->encryptSimple($data);
			case 'INTEGER':
				return $this->encryptInteger($data);
		}
		if ($this->iv) {
			$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->encMethod));
		} else {
			$iv=substr(md5($data,true),0,openssl_cipher_iv_length($this->encMethod));
		}
		$encrypted_string = bin2hex($iv) . openssl_encrypt($this->encSalt . $data, $this->encMethod, $this->encPassword, 0, $iv);
		return str_replace(array('+', '/'), array('-', '_'),base64_encode($encrypted_string));
	}
132712
public function encrypt($str = null, $key = null)
    {
        if (!is_null($key)) {
            $this->setSalt($key);
        }
        srand((double)microtime()*1000000);
        $key_encrypt    = md5(rand(0,32000));
        $count          = 0;
        $tmp            = '';
        for ($ctr=0;$ctr<strlen($str);$ctr++) {
            if ($count==strlen($key_encrypt)) {
                $count=0;
            }
            $tmp.= substr($key_encrypt,$count,1).(substr($str,$ctr,1) ^ substr($key_encrypt,$count,1) );
            $count++;
        }
        return base64_encode(self::getEncryptionKey($tmp));
    }
1045625
public function decrypt($encrypted)
    {
        try {
            $iv = substr($this->key, 0, 16);
            $decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv);
        } catch (Exception $e) {
            return [ErrorCode::$DecryptAESError, null];
        }
        try {
            $pkcEncoder = new PKCS7Encoder();
            $result = $pkcEncoder->decode($decrypted);
            if (strlen($result) < 16) {
                return [ErrorCode::$DecryptAESError, null];
            }
            $content = substr($result, 16, strlen($result));
            $len_list = unpack("N", substr($content, 0, 4));
            $xml_len = $len_list[1];
            return [0, substr($content, 4, $xml_len), substr($content, $xml_len + 4)];
        } catch (Exception $e) {
            return [ErrorCode::$IllegalBuffer, null];
        }
    }
460831
public function decryptData($data)
    {
        if ($this->cryptParams['library'] === 'openssl') {
            switch ($this->cryptParams['type']) {
                case 'symmetric':
                    return $this->decryptSymmetric($data);
                case 'public':
                    return $this->decryptPublic($data);
                case 'private':
                    return $this->decryptPrivate($data);
            }
        }
    }
409779
public function encrypt($data)
    {
        $iv = openssl_random_pseudo_bytes($this->getSize());

        $value = openssl_encrypt(serialize($data), $this->method, $this->key, 0, $iv);

        $mac = $this->hash($iv = base64_encode($iv), $value);

        return base64_encode(json_encode(compact('iv', 'value', 'mac')));
    }
251683
public static function encrypt($data, $adapter = null)
    {
        ($adapter !== null) ? self::setAdapter($adapter) : self::setAdapter(__config()->encryption->driver);

        return self::$adapter->encrypt($data);
    }
87699
public function encrypt($text, $key = null)
    {
        if (null === $key) {
            $key = $this->getEncryptKey();
        }

        $ivSize = $this->getMsCryptIvSize();
        $iv     = mcrypt_create_iv($ivSize, MCRYPT_DEV_RANDOM);

        $cipherText = mcrypt_encrypt(
            $this->getMcryptCipher(),
            $key,
            $text,
            $this->getMcryptMode(),
            $iv
        );

        $cipherText = $iv.$cipherText;

        return base64_encode($cipherText);
    }
780699
public function encrypt($data){
        $maxlength = $this->getMaxEncryptBlockSize($this->publicKey);
        $output='';
        while(strlen($data)){
            $input = substr($data, 0, $maxlength);
            $data = substr($data, $maxlength);
            openssl_public_encrypt($input, $encrypted, $this->publicKey);
            $output .= $encrypted;
        }
        $encryptedData =  base64_encode($output);
        return $encryptedData;
    }
84186
public function encode($data)
    {
        return openssl_encrypt($data, $this->method, $this->key, 0, $this->iv);
    }
858898
public function encrypt($s)
	{
		if(strlen($this->_method) == 0 || strlen($this->_key) == 0)
			return null;
		$options = OPENSSL_RAW_DATA;
		if($this->_padding == parent::PADDING_NONE)
			$options = $options | OPENSSL_NO_PADDING;
		return openssl_encrypt($s, $this->_method, $this->_key, $options,
				$this->_iv);
	}
964641
public function decrypt($encryptedData)
    {
        $this->checkClosed();

        //Check encrypted data
        if (!is_string($encryptedData)) {
            throw new \InvalidArgumentException('Encrypted data must be a string');
        }

        //Base64
        if ($this->base64) {
            if ($this->base64UrlSafe) {
                $encryptedData = strtr($encryptedData, self::$BASE64_URL_SAFE_REPLACE[1], self::$BASE64_URL_SAFE_REPLACE[0]);
            }

            $encryptedData = base64_decode($encryptedData, true);

            if ($encryptedData === false) {
                throw new \InvalidArgumentException('Encrypted data is not a valid base64 string');
            }
        }

        //Encryption
        if ($this->randomInitializationVector) {
            $initializationVector = substr($encryptedData, 0, $this->initializationVectorSize);

            if (strlen($initializationVector) < $this->initializationVectorSize) {
                throw new \InvalidArgumentException('Encrypted data is not long enough to get the initialization vector');
            }

            $encryptedData = substr($encryptedData, $this->initializationVectorSize);
        } else {
            $initializationVector = $this->fixedInitializationVector;
        }
        mcrypt_generic_init($this->module, $this->key, $initializationVector);
        $data = mdecrypt_generic($this->module, $encryptedData);
        $data = rtrim($data, "\0");

        return $data;
    }
1229042
public function prepareRequestBody($requestData)
    {
        $url = parse_url($requestData['url']);

        $headers = [
            'Content-Type: text/xml',
            sprintf('Authorization: Basic %s', base64_encode($requestData['user_login'])),
            sprintf('Content-Length: %s', strlen($requestData['body'])),
            sprintf('User-Agent: %s', $requestData['user_agent']),
        ];

        $contextOptions = [
            'http' => [
                'method'  => $requestData['type'],
                'header'  => implode("\r\n", $headers),
                'content' => $requestData['body'],
                'timeout' => $requestData['timeout']
            ],
            'ssl'  => [
                // DO NOT allow self-signed certificates
                'allow_self_signed' => false,
                // Path to certificate/s PEM files used to validate the server authenticity
                'cafile'            => $requestData['ca_bundle'],
                // Validate Certificates
                'verify_peer'       => true,
                // Abort if the certificate-chain is longer than 5 nodes
                'verify_depth'      => 10,
                // SNI causes errors due to improper handling of alerts by OpenSSL in 0.9.8
                // As many php releases are linked against 0.9.8, its better to disable SNI
                // in case you can't upgrade.
                'SNI_enabled'       => true,
                // You can tweak the accepted Cipher list (if needed)
                'ciphers'           => implode(':', self::getCiphers())
            ]
        ];

        // Note: Mitigate CRIME/BEAST attacks
        if (\Genesis\Utils\Common::compareVersions('5.4.13', '>=')) {
            $contextOptions['ssl']['disable_compression'] = true;
        }

        // Note: PHP does NOT support SAN certs on PHP version < 5.6
        if (\Genesis\Utils\Common::compareVersions('5.6.0', '<')) {
            $contextOptions['ssl']['CN_match']          = $url['host'];
            $contextOptions['ssl']['SNI_server_name']   = $url['host'];
        } else {
            $contextOptions['ssl']['peer_name']         = $url['host'];
            $contextOptions['ssl']['verify_peer_name']  = true;
        }

        $this->streamContext = stream_context_create($contextOptions);

        $this->requestData = $requestData;
    }
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);
            }
        }
    }
284870
public function decryptData($encryptedData, $iv, &$data)
    {
        if (strlen($this->sessionKey) != 24) {
            return \ErrorCode::$IllegalAesKey;
        }
        $aesKey = base64_decode($this->sessionKey);
        if (strlen($iv) != 24) {
            return \ErrorCode::$IllegalIv;
        }
        $aesIV = base64_decode($iv);
        $aesCipher = base64_decode($encryptedData);
        $result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
        $dataObj = json_decode($result);
        if ($dataObj == null) {
            return \ErrorCode::$IllegalBuffer;
        }
        if ($dataObj->watermark->appid != $this->appid) {
            return \ErrorCode::$IllegalBuffer;
        }
        $data = $result;
        return \ErrorCode::$OK;
    }
283286
function decrypt($ciphertext)
    {
        if ($this->engine == CRYPT_ENGINE_OPENSSL) {
            $temp = $this->key;
            $this->key = $this->orig_key;
            $result = parent::decrypt($ciphertext);
            $this->key = $temp;
            return $result;
        }

        return parent::decrypt($ciphertext);
    }
1253292
public function encrypt($value)
    {
        $iv = Str::randomBytes($this->getIvSize());

        $value = \openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);

        if ($value === false) {
            throw new EncryptException('Could not encrypt the data.');
        }

        $mac = $this->hash($iv = base64_encode($iv), $value);

        return base64_encode(json_encode(compact('iv', 'value', 'mac')));
    }