src/Viserio/Component/Cookie/Middleware/EncryptedCookiesMiddleware.php
protected function encrypt(ResponseInterface $response): ResponseInterface
    {
        $cookies = ResponseCookies::fromResponse($response);

        /** @var SetCookie $cookie */
        foreach ($cookies->getAll() as $cookie) {
            $name = $cookie->getName();

            if ($this->isDisabled($name)) {
                continue;
            }

            $cookies        = $cookies->forget($name);
            $encryptedValue = Crypto::encrypt(
                new HiddenString($cookie->getValue()),
                $this->key
            );

            $cookies = $cookies->add(
                $this->duplicate(
                    $cookie,
                    $encryptedValue
                )
            );
        }

        return $cookies->renderIntoSetCookieHeader($response);
    }
protected function encrypt(ResponseInterface $response): ResponseInterface
    {
        $cookies = ResponseCookies::fromResponse($response);

        /** @var SetCookie $cookie */
        foreach ($cookies->getAll() as $cookie) {
            $name = $cookie->getName();

            if ($this->isDisabled($name)) {
                continue;
            }

            $cookies        = $cookies->forget($name);
            $encryptedValue = Crypto::encrypt(
                new HiddenString($cookie->getValue()),
                $this->key
            );

            $cookies = $cookies->add(
                $this->duplicate(
                    $cookie,
                    $encryptedValue
                )
            );
        }

        return $cookies->renderIntoSetCookieHeader($response);
    }
Encrypt the cookies on an outgoing response.

@param \Psr\Http\Message\ResponseInterface $response

@return \Psr\Http\Message\ResponseInterface