__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace Jose\Component\Encryption;
use Jose\Component\Checker\HeaderCheckerManager;
use Jose\Component\Core\JWK;
use Jose\Component\Core\JWKSet;
use Jose\Component\Encryption\Serializer\JWESerializerManager;
use RuntimeException;
use Throwable;
/**
* @see \Jose\Tests\Component\Encryption\JWELoaderTest
*/
class JWELoader
{
public function __construct(
private readonly JWESerializerManager $serializerManager,
private readonly JWEDecrypter $jweDecrypter,
private readonly ?HeaderCheckerManager $headerCheckerManager
) {
}
/**
* Returns the JWE Decrypter object.
*/
public function getJweDecrypter(): JWEDecrypter
{
return $this->jweDecrypter;
}
/**
* Returns the header checker manager if set.
*/
public function getHeaderCheckerManager(): ?HeaderCheckerManager
{
return $this->headerCheckerManager;
}
/**
* Returns the serializer manager.
*/
public function getSerializerManager(): JWESerializerManager
{
return $this->serializerManager;
}
/**
* This method will try to load and decrypt the given token using a JWK. If succeeded, the methods will populate the
* $recipient variable and returns the JWE.
*/
public function loadAndDecryptWithKey(string $token, JWK $key, ?int &$recipient): JWE
{
$keyset = new JWKSet([$key]);
return $this->loadAndDecryptWithKeySet($token, $keyset, $recipient);
}
/**
* This method will try to load and decrypt the given token using a JWKSet. If succeeded, the methods will populate
* the $recipient variable and returns the JWE.
*/
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 (Throwable) {
// Nothing to do. Exception thrown just after
}
throw new RuntimeException('Unable to load and decrypt the token.');
}
private function processRecipient(JWE &$jwe, JWKSet $keyset, int $recipient): bool
{
try {
if ($this->headerCheckerManager !== null) {
$this->headerCheckerManager->check($jwe, $recipient);
}
return $this->jweDecrypter->decryptUsingKeySet($jwe, $keyset, $recipient);
} catch (Throwable) {
return false;
}
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Algorithm | Folder | 0775 |
|
|
| Compression | Folder | 0775 |
|
|
| Serializer | Folder | 0775 |
|
|
| JWE.php | File | 5.33 KB | 0664 |
|
| JWEBuilder.php | File | 22.38 KB | 0664 |
|
| JWEBuilderFactory.php | File | 2.04 KB | 0664 |
|
| JWEDecrypter.php | File | 12 KB | 0664 |
|
| JWEDecrypterFactory.php | File | 1.79 KB | 0664 |
|
| JWELoader.php | File | 2.7 KB | 0664 |
|
| JWELoaderFactory.php | File | 1.57 KB | 0664 |
|
| JWETokenSupport.php | File | 887 B | 0664 |
|
| Recipient.php | File | 1.27 KB | 0664 |
|