Inheritance: implements Jose\Factory\JWEFactoryInterface
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function encrypt($payload, array $encryption_protected_headers, Object\JWKInterface $encryption_key)
 {
     Assertion::true($this->isEncryptionSupportEnabled(), 'The encryption support is not enabled');
     $jwe = Factory\JWEFactory::createJWE($payload, $encryption_protected_headers);
     $jwe = $jwe->addRecipientInformation($encryption_key);
     $this->encrypter->encrypt($jwe);
     return $jwe->toCompactJSON(0);
 }
 /**
  * Create a JSON Web Token.
  *
  * @param array $payload
  * @return string
  * @throws JWTException
  */
 public function encode(array $payload)
 {
     try {
         $token = JWEFactory::createJWEToCompactJSON($payload, $this->encryptionKey, ['alg' => 'dir', 'enc' => $this->encryptionKey->get('alg'), 'zip' => 'DEF']);
         return JWSFactory::createJWSToCompactJSON($token, $this->signatureKey, ['alg' => $this->signatureKey->get('alg'), 'zip' => 'DEF']);
     } catch (Exception $e) {
         throw new JWTException('Could not create token: ' . $e->getMessage());
     }
 }