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.
The CompactEncrypt class is used to build and encrypt Compact JWE strings.
This class is exported (as a named export) from the main 'jose' module entry point as well as
from its subpath export 'jose/jwe/compact/encrypt'.
const jwe = await new jose.CompactEncrypt(
new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
)
.setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
.encrypt(publicKey)
console.log(jwe)▸ new CompactEncrypt(plaintext): CompactEncrypt
CompactEncrypt constructor
| Parameter | Type | Description |
|---|---|---|
plaintext |
Uint8Array |
Binary representation of the plaintext to encrypt. |
CompactEncrypt
▸ encrypt(key, options?): Promise<string>
Encrypts and resolves the value of the Compact JWE string.
| Parameter | Type | Description |
|---|---|---|
key |
Uint8Array | CryptoKey | JWK | KeyObject |
Public Key or Secret to encrypt the JWE with. See Algorithm Key Requirements. |
options? |
EncryptOptions |
JWE Encryption options. |
Promise<string>
▸ setContentEncryptionKey(cek): this
Sets a content encryption key to use, by default a random suitable one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
| Parameter | Type | Description |
|---|---|---|
cek |
Uint8Array |
JWE Content Encryption Key. |
this
You should not use this method. It is only really intended for test and vector validation purposes.
▸ setInitializationVector(iv): this
Sets the JWE Initialization Vector to use for content encryption, by default a random suitable one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
| Parameter | Type | Description |
|---|---|---|
iv |
Uint8Array |
JWE Initialization Vector. |
this
You should not use this method. It is only really intended for test and vector validation purposes.
▸ setKeyManagementParameters(parameters): this
Sets the JWE Key Management parameters to be used when encrypting.
(ECDH-ES) Use of this method is needed for ECDH based algorithms to set the "apu" (Agreement PartyUInfo) or "apv" (Agreement PartyVInfo) parameters.
| Parameter | Type | Description |
|---|---|---|
parameters |
JWEKeyManagementHeaderParameters |
JWE Key Management parameters. |
this
▸ setProtectedHeader(protectedHeader): this
Sets the JWE Protected Header on the CompactEncrypt object.
| Parameter | Type | Description |
|---|---|---|
protectedHeader |
CompactJWEHeaderParameters |
JWE Protected Header object. |
this