This method will try to decrypt the given JWE and recipient using a JWK.

@param JWE $jwe       A JWE object to decrypt
@param JWK $jwk       The key used to decrypt the input
@param int $recipient The recipient used to decrypt the token
658
public function decryptUsingKey(JWE &$jwe, JWK $jwk, int $recipient): bool
    {
        $jwkset = new JWKSet([$jwk]);

        return $this->decryptUsingKeySet($jwe, $jwkset, $recipient);
    }
406646
public function loadAndDecryptWithKey(string $token, JWK $key, ?int &$recipient): JWE
    {
        $keyset = JWKSet::createFromKeys([$key]);

        return $this->loadAndDecryptWithKeySet($token, $keyset, $recipient);
    }
471790
public function getDecodedToken(string $jwt)
    {
        try {
            /** @noinspection PhpUnusedLocalVariableInspection */
            [$headb64, $bodyb64, $cryptob64] = \explode('.', $jwt);
            $decodedToken = \json_decode(JWT::urlsafeB64Decode($bodyb64));

            /** @noinspection NullPointerExceptionInspection */
            JWT::decode($jwt, $this->findTenant($decodedToken->iss)->getSharedSecret(), ['HS256']);

            return $decodedToken;
        } catch (\Throwable $e) {
            throw new AuthenticationException($e->getMessage());
        }
    }
962760
public function loadAndDecryptWithKeySet(string $token, JWKSet $keyset, ?int &$recipient): JWE
    {
        try {
            $jwe = $this->serializerManager->unserialize($token);
            $nbRecipients = $jwe->countRecipients();
            for ($i = 0; $i < $nbRecipients; ++$i) {
                if ($this->processRecipient($jwe, $keyset, $i)) {
                    $recipient = $i;

                    return $jwe;
                }
            }
        } catch (\Exception $e) {
            // Nothing to do. Exception thrown just after
        }

        throw new \Exception('Unable to load and decrypt the token.');
    }
1006901
private function getKeyManagementMode(JWEInterface $jwe)
    {
        $mode = null;
        $recipients = $jwe->getRecipients();

        foreach ($recipients as $recipient) {
            $complete_headers = array_merge($jwe->getSharedProtectedHeaders(), $jwe->getSharedHeaders(), $recipient->getHeaders());
            Assertion::keyExists($complete_headers, 'alg', 'Parameter "alg" is missing.');

            $key_encryption_algorithm = $this->getJWAManager()->getAlgorithm($complete_headers['alg']);
            Assertion::isInstanceOf($key_encryption_algorithm, Algorithm\KeyEncryptionAlgorithmInterface::class, sprintf('The key encryption algorithm "%s" is not supported or not a key encryption algorithm instance.', $complete_headers['alg']));

            if (null === $mode) {
                $mode = $key_encryption_algorithm->getKeyManagementMode();
            } else {
                Assertion::true($this->areKeyManagementModesCompatible($mode, $key_encryption_algorithm->getKeyManagementMode()), 'Foreign key management mode forbidden.');
            }
        }

        return $mode;
    }
402560
public function decryptMsg($xml, $msg_signature = null, $timeStamp = null, $nonce = null)
    {
        $appId          = Api::getAppId();
        $token          = Api::getToken();
        $encodingAesKey = Api::getEncoding_Aes_Key();

        $msg_signature = !empty($msg_signature) ? $msg_signature : $_GET['msg_signature'];
        $timeStamp     = !empty($timeStamp) ? $timeStamp : $_GET['timestamp'];
        $nonce         = !empty($nonce) ? $nonce : $_GET['nonce'];

        $pc  = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
        $msg = '';

        $errCode = $pc->decryptMsg($msg_signature, $timeStamp, $nonce, $xml, $msg);

        if ($errCode == 0) {
            return $msg;
        } else {
            exit($errCode);
        }
    }
745159
private function decryptAssertion(Object\JWEInterface $jwe, Object\JWKSetInterface $encryption_key_set)
    {
        $this->decrypter->decryptUsingKeySet($jwe, $encryption_key_set);

        $jws = $this->loader->load($jwe->getPayload());
        Assertion::isInstanceOf($jws, Object\JWSInterface::class, 'The encrypted assertion does not contain a JWS.');

        return $jws;
    }
407876
public function decrypt($text, $email)
	{
		$key = $this->hasher->key($email);

		return $this->crypter->decrypt($text, $key);
	}
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);
    }
1347587
private function getCompressionMethod(JWEInterface $jwe)
    {
        $method = null;
        $nb_recipients = $jwe->countRecipients();

        for ($i = 0; $i < $nb_recipients; ++$i) {
            $complete_headers = array_merge($jwe->getSharedProtectedHeaders(), $jwe->getSharedHeaders(), $jwe->getRecipient($i)->getHeaders());
            if (array_key_exists('zip', $complete_headers)) {
                if (null === $method) {
                    if (0 === $i) {
                        $method = $complete_headers['zip'];
                    } else {
                        throw new \InvalidArgumentException('Inconsistent "zip" parameter.');
                    }
                } else {
                    Assertion::eq($method, $complete_headers['zip'], 'Inconsistent "zip" parameter.');
                }
            } else {
                Assertion::eq(null, $method, 'Inconsistent "zip" parameter.');
            }
        }

        if (null === $method) {
            return;
        }

        $compression_method = $this->getCompressionManager()->getCompressionAlgorithm($method);
        Assertion::isInstanceOf($compression_method, Compression\CompressionInterface::class, sprintf('Compression method "%s" not supported.', $method));

        return $compression_method;
    }
1129931
public function addKeyRecipient($recipientId, $publicKey)
    {
        try {
            $this->cipher->addKeyRecipient($recipientId, $publicKey);

            return $this;
        } catch (Exception $e) {
            throw new CipherException($e->getMessage(), $e->getCode());
        }
    }
517793
private function getOpenSSLSignature(JWKInterface $key, $data)
    {
        $pem = (new ECKey($key))->toPEM();
        $result = openssl_sign($data, $signature, $pem, $this->getHashAlgorithm());

        Assertion::true($result, 'Signature failed');

        $asn = ASNObject::fromBinary($signature);
        Assertion::isInstanceOf($asn, Sequence::class, 'Invalid signature');

        $res = '';
        foreach ($asn->getChildren() as $child) {
            Assertion::isInstanceOf($child, Integer::class, 'Invalid signature');
            $res .= str_pad($this->convertDecToHex($child->getContent()), $this->getSignaturePartLength(), '0', STR_PAD_LEFT);
        }

        return $this->convertHexToBin($res);
    }
962201
def _decrypt(self, rj, token):
        
        if self.iss:
            keys = self.key_jar.get_jwt_decrypt_keys(rj.jwt, aud=self.iss)
        else:
            keys = self.key_jar.get_jwt_decrypt_keys(rj.jwt)
        return rj.decrypt(token, keys=keys)
51010
private function getPHPECCSignature(JWKInterface $key, $data)
    {
        $p = $this->getGenerator();
        $d = $this->convertBase64ToGmp($key->get('d'));
        $hash = $this->convertHexToGmp(hash($this->getHashAlgorithm(), $data));

        $k = RandomGeneratorFactory::getRandomGenerator()->generate($p->getOrder());

        $signer = EccFactory::getSigner();

        $private_key = $p->getPrivateKeyFrom($d);
        $signature = $signer->sign($private_key, $hash, $k);

        $part_length = $this->getSignaturePartLength();

        $R = str_pad($this->convertDecToHex($signature->getR()), $part_length, '0', STR_PAD_LEFT);
        $S = str_pad($this->convertDecToHex($signature->getS()), $part_length, '0', STR_PAD_LEFT);

        return $this->convertHexToBin($R.$S);
    }
1152442
public static function DecryptRandom ($encoded_message, $password, $salt, $hmac_key, $secret_key_length = self::SECRET_KEY_LENGTH, $algo = self::DEFAULT_HASH_ALGORITHM) {
		//passwrod1
		$password1 = static::CreateForwardPassword($encoded_message, $password, $salt, $hmac_key, $secret_key_length, $algo);
		if (strlen($password1) > 56) {
			$password1 = substr($password1, -56);
		}

		//binary passwrod 1
		$binary_passwrod_1 = static::CreateForwardBinaryPassword($encoded_message, $password, $salt, $hmac_key, $secret_key_length, $algo);

		//複合テスト
		//逆加工
		$encoded_message = trim($encoded_message);

		//secret key
		$secret_key = substr($encoded_message, $secret_key_length, $secret_key_length);

		//インプット
		$encoded_message = substr($encoded_message, 0, $secret_key_length) . substr($encoded_message, strlen($secret_key) * 2);

		//passwrod2
		$password2 = Hash::HmacStringStretching($secret_key_length, $password, $secret_key);
		if (strlen($password2) > 56) {
			$password2 = substr($password2, -56);
		}

		//binary passwrod 2
		$binary_passwrod_2 = Hash::HmacBinaryStretching($secret_key_length, $password, $secret_key);

		//ダミー
		$encoded_message_length = strlen($encoded_message);
		$encoded_message = str_pad($encoded_message, $encoded_message_length + $encoded_message_length % 4,  '=');
		$encoded_message = CompressionGz::UnCompress(static::DecryptMessage(base64_decode($encoded_message), $password2, static::GetRandomEncryptOptions($binary_passwrod_2)));

		//マスタ
		return static::DecryptMessage(base64_decode($encoded_message), $password1, static::GetRandomEncryptOptions($binary_passwrod_1));
	}
1364575
public function decode($jwsString)
    {
        $components = explode('.', $jwsString);
        if (count($components) !== 3) {
            throw new MalformedSignatureException('JWS string must contain 3 dot separated component.');
        }

        try {
            $headers = Json::decode(Base64Url::decode($components[0]));
            $payload = Json::decode(Base64Url::decode($components[1]));
        } catch (\InvalidArgumentException $e) {
            throw new MalformedSignatureException("Cannot decode signature headers and/or payload");
        }

        return [
            'headers' => $headers,
            'payload' => $payload
        ];
    }
642999
public function verifyWithKey(JWSInterface $jws, JWKInterface $jwk, $detached_payload = null, &$recipient_index = null)
    {
        $this->log(LogLevel::DEBUG, 'Trying to verify the JWS with the key', ['jws' => $jws, 'jwk' => $jwk, 'detached_payload' => $detached_payload]);
        $jwk_set = new JWKSet();
        $jwk_set->addKey($jwk);

        $this->verifySignatures($jws, $jwk_set, $detached_payload, $recipient_index);
    }