Jose\Factory\JWEFactory::createJWEToCompactJSON PHP Method

createJWEToCompactJSON() public static method

public static createJWEToCompactJSON ( $payload, Jose\Object\JWKInterface $recipient_key, array $shared_protected_headers )
$recipient_key Jose\Object\JWKInterface
$shared_protected_headers array
    public static function createJWEToCompactJSON($payload, JWKInterface $recipient_key, array $shared_protected_headers)
    {
        $jwe = self::createJWEAndEncrypt($payload, $recipient_key, $shared_protected_headers, [], [], null);
        return $jwe->toCompactJSON(0);
    }

Usage Example

 /**
  * 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());
     }
 }