private function getEncryptionKey(ServerRequestInterface $request) : EncryptionKeyInterface
    {
        if (!$request->hasHeader('x-hashid')) {
            throw new Exception('Unable to decrypt request.');
        }

        $hashKey = $request->getHeaderLine('x-hashid');

        try {
            $result = $this->cache->get($hashKey);

            if (!$result) {
                throw new Exception('Unable to extract key from cache.');
            }

            if (\function_exists('igbinary_unserialize')) {
                return \igbinary_unserialize($result);
            }

            return \unserialize($result);
        } catch (InvalidArgumentException $e) {
            throw new Exception('Unable to decrypt request.', null, $e);
        }
    }