Back to Jose

Class: GeneralEncrypt

docs/jwe/general/encrypt/classes/GeneralEncrypt.md

6.2.23.8 KB
Original Source

Class: GeneralEncrypt

💗 Help the project

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 GeneralEncrypt class is used to build and encrypt 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'.

Example

js
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)

Constructors

Constructor

â–¸ new GeneralEncrypt(plaintext): GeneralEncrypt

GeneralEncrypt constructor

Parameters

ParameterTypeDescription
plaintextUint8ArrayBinary representation of the plaintext to encrypt.

Returns

GeneralEncrypt

Methods

addRecipient()

â–¸ addRecipient(key, options?): Recipient

Adds an additional recipient for the General JWE object.

Parameters

ParameterTypeDescription
keyUint8Array | CryptoKey | JWK | KeyObjectPublic Key or Secret to encrypt the Content Encryption Key for the recipient with. See Algorithm Key Requirements.
options?CritOptionJWE Encryption options.

Returns

Recipient


encrypt()

â–¸ encrypt(): Promise<GeneralJWE>

Encrypts and resolves the value of the General JWE object.

Returns

Promise<GeneralJWE>


setAdditionalAuthenticatedData()

â–¸ setAdditionalAuthenticatedData(aad): this

Sets the Additional Authenticated Data on the GeneralEncrypt object.

Parameters

ParameterTypeDescription
aadUint8ArrayAdditional Authenticated Data.

Returns

this


setProtectedHeader()

â–¸ setProtectedHeader(protectedHeader): this

Sets the JWE Protected Header on the GeneralEncrypt object.

Parameters

ParameterTypeDescription
protectedHeaderJWEHeaderParametersJWE Protected Header object.

Returns

this


setSharedUnprotectedHeader()

â–¸ setSharedUnprotectedHeader(sharedUnprotectedHeader): this

Sets the JWE Shared Unprotected Header on the GeneralEncrypt object.

Parameters

ParameterTypeDescription
sharedUnprotectedHeaderJWEHeaderParametersJWE Shared Unprotected Header object.

Returns

this