When you need to encrypt the same payload for several audiences, you may want to do it at once. The JWE Builder supports multiple recipients.
With the example below, we will create an encrypted token for three different recipients using three different key encryption algorithms.
- The content encryption algorithm MUST be the same for all recipients.
- The Key Management Modes of the key encryption algorithms MUST be compatible (see table below).
->withSharedProtectedHeader(['enc' => 'A128GCM'])
->addRecipient($recipient_key_1, ['alg' => 'RSA1_5'])
->addRecipient($recipient_key_2, ['alg' => 'RSA-OAEP-256'])
Note: when an unprotected header is set, the Compact Serialization mode is not available.
Each Key Encryption Algorithm has its own Key Management Mode.