docs/jwe/general/encrypt/classes/GeneralEncrypt.md
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.
Builds and encrypts General JWE objects.
This class is exported (as a named export) from the main 'jose' module entry point as well as
from its subpath export 'jose/jwe/general/encrypt'.
const jwe = await new jose.GeneralEncrypt(
new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
)
.setProtectedHeader({ enc: 'A256GCM' })
.addRecipient(ecPublicKey)
.setUnprotectedHeader({ alg: 'ECDH-ES+A256KW' })
.addRecipient(rsaPublicKey)
.setUnprotectedHeader({ alg: 'RSA-OAEP-384' })
.encrypt()
console.log(jwe)
â–¸ new GeneralEncrypt(plaintext): GeneralEncrypt
Creates a General JWE encryptor.
| Parameter | Type | Description |
|---|---|---|
plaintext | Uint8Array | Binary representation of the plaintext to encrypt. |
GeneralEncrypt
â–¸ addRecipient(key, options?): Recipient
Adds a recipient and returns its configuration.
| Parameter | Type | Description |
|---|---|---|
key | KeyInput | Public key or shared secret. See Algorithm Key Requirements. |
options? | CritOption | JWE Encryption options. |
â–¸ encrypt(): Promise<GeneralJWE>
Encrypts the plaintext as a General JWE.
â–¸ setAdditionalAuthenticatedData(aad): this
Sets additional data to authenticate without encrypting it.
| Parameter | Type | Description |
|---|---|---|
aad | Uint8Array | Additional Authenticated Data. |
this
â–¸ setProtectedHeader(protectedHeader): this
Sets the JWE Protected Header. May only be called once.
| Parameter | Type | Description |
|---|---|---|
protectedHeader | JWEHeaderParameters | JWE Protected Header object. |
this
â–¸ setSharedUnprotectedHeader(sharedUnprotectedHeader): this
Sets the JWE Shared Unprotected Header. May only be called once.
| Parameter | Type | Description |
|---|---|---|
sharedUnprotectedHeader | JWEHeaderParameters | JWE Shared Unprotected Header object. |
this