Prepares data to be written to storage

@param string $data The data to prepare
@return string The prepared data
@throws LogicException Thrown if using encryption but an encrypter has not been set
336545
protected function prepareForWrite(string $data) : string
    {
        if ($this->usesEncryption) {
            if ($this->encrypter === null) {
                throw new LogicException('Encrypter not set in session handler');
            }

            try {
                return $this->encrypter->encrypt($data);
            } catch (SessionEncryptionException $ex) {
                return '';
            }
        } else {
            return $data;
        }
    }
101338
public function encrypt($data): string
    {
        if (!$this->password)
        {
            return JSON::encode($data);
        }

        return $this->security()
            ->encrypt(JSON::encode($data));
    }
136854
public function prepend($data) {

		if(false === is_string($data)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
		}

		if(false !== $this -> file -> getExists()) {

			$this -> refresh();

    		if(false === $this -> file -> getWritable()) {
    			trigger_error(sprintf('File "%s" is not writable', $this -> file -> getBasepath()), E_USER_ERROR);
	    	}

    		$handle 	= fopen($this -> file -> getBasepath(), 'r+');
			$len 		= strlen($data);
			$final_len 	= filesize($this -> file -> getBasepath()) + $len;
			$cache_old 	= fread($handle, $len);
			
			rewind($handle);
			
			$i = 1;
			
			while(ftell($handle) < $final_len) {

				fwrite($handle, $data);
				
				$data 		= $cache_old;
				$cache_old 	= fread($handle, $len);

				fseek($handle, $i * $len);
				
				$i++;
			}
		}

		return $this;
	}
545778
static public function encode($data)
	{
	    if (is_string($data)) {
	        $data = str_replace(array("\r\n"), "", $data);
	        if (strpos($data, '{') ===0 || strpos($data, '[') ===0) {
	            $data = json_decode($data, true);
	        }
	    }
	    
		return json_encode($data);
	}
880217
public function decode($data)
    {

        // Make sure we have a valid data string.
        $mod = strlen($data) % 8;
        if ($mod === 1 || $mod === 3 || $mod === 6) {
            throw new \DomainException('Invalid input.');
        }

        // Convert the data to a binary string.
        $bits = '';
        foreach (str_split(strtoupper($data)) as $char) {
            $index = strpos($this->getConfig('alphabet'), $char);
            if ($index === false) {
                throw new \DomainException('Invalid character in input.');
            }
            $bits .= sprintf('%05b', $index);
        }

        // Make sure padding is all zeroes.
        if (preg_match('/[^0]/', substr($bits, 0 - strlen($bits) % 8)) === 1) {
            throw new \DomainException('Invalid input.');
        }

        // Decode the binary string.
        $output = '';
        foreach (str_split($bits, 8) as $chunk) {
            $output .= chr(bindec($chunk));
        }
        return rtrim($output);

    }
971075
public function write($data)
    {
        $this->contentLength += strlen($data);
        $this->data .= $data;

        return $this;
    }
71140
private function encryptPrivate($data)
    {
        if (!openssl_private_encrypt($data, $encrypted, $this->key, $this->cryptParams['padding'])) {
            throw new Exception('Failure encrypting Data (openssl private) - ' . openssl_error_string());
        }
        return $encrypted;
    }
1029911
public function encrypt($data)
    {
        // Get module
        $module = mcrypt_module_open($this->cipher, '', $this->mode, '');

        // Create initialization vector
        $vector = mcrypt_create_iv(mcrypt_enc_get_iv_size($module), MCRYPT_DEV_URANDOM);

        // Validate key length
        $this->validateKeyLength($this->key, $module);

        // Initialize encryption
        $initResult = mcrypt_generic_init($module, $this->key, $vector);

        if (!is_null($initResult)) {
            $this->throwInitError($initResult, 'encrypt');
        }

        // Encrypt
        $encryptedData = mcrypt_generic($module, $data);

        // Deinitialize encryption
        mcrypt_generic_deinit($module);

        // Ensure integrity of encrypted data with HMAC hash
        $hmac = $this->getHmac($encryptedData);

        return implode('|', array(base64_encode($vector), base64_encode($encryptedData), $hmac));
    }
754169
public function encode($data)
    {

        // Convert the data to a binary string.
        $bits = '';
        foreach (str_split($data) as $char) {
            $bits .= sprintf('%08b', ord($char));
        }

        // Make sure the string length is a multiple of 5, padding if needed.
        $len = strlen($bits);
        $mod = $len % 5;
        if ($mod !== 0) {
            $bits = str_pad($bits, $len + 5 - $mod, '0', STR_PAD_RIGHT);
        }

        // Split the binary string into 5-bit chunks and encode each chunk.
        $output = '';
        foreach (str_split($bits, 5) as $chunk) {
            $output .= substr($this->getConfig('alphabet'), bindec($chunk), 1);
        }

        return $output;

    }
912706
public function format(&$data) {
		$data = $this->normalize($data);
		$data = $this->convertToString($data);

		return $data;
	}
1066655
private function encrypt($data)
    {
        $bin_key = pack("H*", substr($this->secret_key, 8));
        $aes_key = substr($bin_key, 0, 16);
        $salt = substr($bin_key, 16, 16);
        $iv = openssl_random_pseudo_bytes(16);
        $encrypted = openssl_encrypt($data, 'aes-128-cbc', $aes_key, true, $iv);
        $digest = hash_hmac('sha256', $data . $iv, $salt, true);
        return base64_encode($iv . $digest . $encrypted);
    }
597350
public function encrypt($data)
    {
        return openssl_encrypt($data, $this->algorithm, $this->secret, 0, $this->iv);
    }
243179
public function delete(DataAbstract $data)
    {
        foreach ($this->primaryKeys as $key) {
            $this->addWhere($key, $this->getDataValue($data, $key));
        }

        $where = $this->getQueryWhere();

        if (empty($where)) {
            throw new \LogicException(__METHOD__ . '| Where restriction is empty for current DELETE query !');
        }

        $query     = 'DELETE FROM ' . $this->getTable() . ' ' . $this->getQueryWhere();
        $statement = $this->db->prepare($query);
        $statement->execute($this->binds);

        //~ Reset some data
        $data->setExists(false);
        $data->resetUpdated();

        //~ Clear
        $this->clear();
        $this->deleteCache($data);

        return $this;
    }
680979
private function serialize($data)
    {
        if ($this->type == 'db') {
            return $this->db->encode($data, $this->packed);
        }

        return $this->packed ? serialize($data) : $data;
    }
273730
protected function prepareData(array $data)
	{
		$data = array_merge(array(
			'name'       => null,
			'email'      => null,
			'username'   => null,
			'id'         => null,
			'text'       => null,
			'ip'         => null,
			'user_agent' => null
		), $data);

		$data['original_text'] = $data['text'];

		if ($this->stringProcessor)
		{
			$data['text'] = $this->stringProcessor->prepare($data['text']);
		}

		return $data;
	}
945992
public function encrypt($data)
    {
        $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
        $token = base64_encode($nonce.sodium_crypto_secretbox($data, $nonce, $this->key).'&&'.$this->key);

        return $token;
    }
196328
public function prepareData($data = [])
    {
        return (array) ($this->data instanceof Closure ? call_user_func($this->data, $this, $data) : $this->data);
    }