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;
        }
    }