@param string $jws

@return string
507253
public function encrypt(string $jws): string
    {
        $headers = $this->getEncryptionHeader();
        $encryptionKey = $this->encryptionKeyset->get($this->encryptionKeyIndex);

        if ($encryptionKey->has('kid')) {
            $headers['kid'] = $encryptionKey->get('kid');
        }

        $jwe = $this->jweBuilder
            ->create()
            ->withPayload($jws)
            ->withSharedProtectedHeader($headers)
            ->addRecipient($encryptionKey)
            ->build();

        $serializer = new JWECompactSerializer(new StandardConverter());

        return $serializer->serialize($jwe, 0);
    }
434365
def _wrap_in_jws(self, nonce, obj):
        
        with LOG_JWS_SIGN(key_type=self._key.typ, alg=self._alg.name,
                          nonce=nonce):
            jobj = obj.json_dumps().encode()
            return (
                JWS.sign(
                    payload=jobj, key=self._key, alg=self._alg, nonce=nonce)
                .json_dumps()
                .encode())
932753
private function presenter2path($s)
	{
		$s = strtr($s, ':', '.');
		$s = preg_replace('#([^.])(?=[A-Z])#', '$1-', $s);
		$s = strtolower($s);
		$s = rawurlencode($s);
		return $s;
	}
960773
public function serialize(string $name, JWE $jws, ?int $recipientIndex = null): string
    {
        if (!\array_key_exists($name, $this->serializers)) {
            throw new \InvalidArgumentException(\sprintf('Unsupported serializer "%s".', $name));
        }

        return ($this->serializers[$name])->serialize($jws, $recipientIndex);
    }
1367226
public static function escapeJidLocalpart($s)
    {
        $result = '';

        $chars = [' ', '"', '&', '\'', '/', ':', '<', '>', '@'];
        $escapes = ['20', '22', '26', '27', '2f', '3a', '3c', '3e', '40', '5c'];

        for($i = 0; $i < strlen($s); $i++) {
            if($s{$i} === '\\') {
                if(in_array($s{$i+1}.$s{$i+2}, $escapes)) {
                    $result .= '\\5c';
                } else {
                    $result .= $s{$i};
                }
            } else if(in_array($s{$i}, $chars)) {
                $result .= '\\'.dechex(ord($s{$i}));
            } else {
                $result .= $s{$i};
            }
        }

        return $result;
    }
995346
public function loadAndVerifyWithKey(string $token, JWK $key, ?int &$signature, ?string $payload = null): JWS
    {
        $keyset = JWKSet::createFromKeys([$key]);

        return $this->loadAndVerifyWithKeySet($token, $keyset, $signature, $payload);
    }
1159048
private function getInputToSign(JWSInterface $jws, SignatureInterface $signature)
    {
        $this->checkB64HeaderAndCrit($signature);
        $encoded_protected_headers = $signature->getEncodedProtectedHeaders();
        $payload = $jws->getPayload();
        if (!$signature->hasProtectedHeader('b64') || true === $signature->getProtectedHeader('b64')) {
            $encoded_payload = Base64Url::encode(is_string($payload) ? $payload : json_encode($payload));

            return sprintf('%s.%s', $encoded_protected_headers, $encoded_payload);
        }

        return sprintf('%s.%s', $encoded_protected_headers, $payload);
    }
812359
public function encode(array $payload)
    {
        // Remove the signature on the builder instance first.
        $this->builder->unsign();

        try {
            foreach ($payload as $key => $value) {
                $this->builder->set($key, $value);
            }
            $this->builder->sign($this->signer, $this->getSigningKey());
        } catch (Exception $e) {
            throw new JWTException('Could not create token: '.$e->getMessage(), $e->getCode(), $e);
        }

        return (string) $this->builder->getToken();
    }
456696
public function encode(JWT $jwt)
    {
        $this->jwt = $jwt;
        $token     = Codec::encode($jwt->getClaims(), $this->secret);

        return $token;
    }
535252
private function decrypt(string $token): string
    {
        $serializer = new JWECompactSerializer(new StandardConverter());
        $jwe = $serializer->unserialize($token);
        $this->encryptionHeaderCheckerManager->check($jwe, 0);
        if (false === $this->jweLoader->decryptUsingKeySet($jwe, $this->encryptionKeyset, 0)) {
            throw new JWTDecodeFailureException('decoding_error', 'An error occurred while trying to decrypt the JWT token.');
        }

        return $jwe->getPayload();
    }
1008851
public function load(string $token, JWKSet $encryptionKeySet, JWKSet $signatureKeySet, ?int &$signature = null): JWS
    {
        $recipient = null;
        $jwe = $this->jweLoader->loadAndDecryptWithKeySet($token, $encryptionKeySet, $recipient);
        $this->checkContentTypeHeader($jwe, $recipient);
        if (null === $jwe->getPayload()) {
            throw new \InvalidArgumentException('The token has no payload.');
        }

        return $this->jwsLoader->loadAndVerifyWithKeySet($jwe->getPayload(), $signatureKeySet, $signature);
    }
25510
function _getAttrString($attributes)
    {
        $strAttr = '';

        if (is_array($attributes)) {
            foreach ($attributes as $key => $value) {
                $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
            }
        }
        return $strAttr;
    }
659508
public function encode(array $headers): string {
        // @TODO implementation is deliberately primitive... [doesn't use any dynamic table...]
        $output = "";

        foreach ($headers as $name => $values) {
            foreach ((array) $values as $value) {
                if (isset(self::$indexMap[$name])) {
                    $index = self::$indexMap[$name];
                    if ($index < 0x10) {
                        $output .= \chr($index);
                    } else {
                        $output .= "\x0f" . \chr($index - 0x0f);
                    }
                } elseif (\strlen($name) < 0x7f) {
                    $output .= "\0" . \chr(\strlen($name)) . $name;
                } else {
                    $output .= "\0\x7f" . self::encodeDynamicInteger(\strlen($name) - 0x7f) . $name;
                }

                if (\strlen($value) < 0x7f) {
                    $output .= \chr(\strlen($value)) . $value;
                } else {
                    $output .= "\x7f" . self::encodeDynamicInteger(\strlen($value) - 0x7f) . $value;
                }
            }
        }

        return $output;
    }
1203749
private function getHypertextString($routes = [])
    {
        // Check if we have routes
        if (!$routes) {
            return '';
        }

        // Loop through the routes and add them to the string
        $str = "links: \n";
        foreach ($routes as $name => $route) {
            $str .= "\trel: {$name}. href: {$route}.\n";
        }
        return $str;
    }
982358
private function extractEncoderKey(array $headers): string
    {
        /** @var string $encoderKey */
        $encoderKey = $headers[Transport::SERVICE_BUS_SERIALIZER_HEADER] ?? self::DEFAULT_DECODER;

        return $encoderKey;
    }
481823
public function encode(array $payload)
    {
        try {
            $this->jws->setPayload($payload)->sign($this->getSigningKey(), $this->getPassphrase());

            return (string) $this->jws->getTokenString();
        } catch (Exception $e) {
            throw new JwTException('Could not create token: '.$e->getMessage(), $e->getCode(), $e);
        }
    }
251098
public function getPayload($token)
    {
        try {
            $jws = SimpleJWS::load($token);

            return $jws->getPayload();
        } catch (\InvalidArgumentException $ex) {
            throw new ProgrammerException('Unable to read jws token.', ProgrammerException::JWS_INVALID_TOKEN_FORMAT);
        }
    }