Back to Jose

Class: FlattenedEncrypt

docs/jwe/flattened/encrypt/classes/FlattenedEncrypt.md

6.2.95.6 KB
Original Source

Class: FlattenedEncrypt

💗 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 FlattenedEncrypt class is used to build and encrypt Flattened 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/flattened/encrypt'.

Example

js
const jwe = await new jose.FlattenedEncrypt(
  new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
)
  .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
  .setAdditionalAuthenticatedData(new TextEncoder().encode('The Fellowship of the Ring'))
  .encrypt(publicKey)

console.log(jwe)

Constructors

Constructor

â–¸ new FlattenedEncrypt(plaintext): FlattenedEncrypt

FlattenedEncrypt constructor

Parameters

ParameterTypeDescription
plaintextUint8ArrayBinary representation of the plaintext to encrypt.

Returns

FlattenedEncrypt

Methods

encrypt()

â–¸ encrypt(key, options?): Promise<FlattenedJWE>

Encrypts and resolves the value of the Flattened JWE object.

Parameters

ParameterTypeDescription
keyKeyInputPublic Key or Secret to encrypt the JWE with. See Algorithm Key Requirements.
options?EncryptOptionsJWE Encryption options.

Returns

Promise<FlattenedJWE>


setAdditionalAuthenticatedData()

â–¸ setAdditionalAuthenticatedData(aad): this

Sets the Additional Authenticated Data on the FlattenedEncrypt object.

Parameters

ParameterTypeDescription
aadUint8ArrayAdditional Authenticated Data.

Returns

this


setContentEncryptionKey()

â–¸ 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.

Parameters

ParameterTypeDescription
cekUint8ArrayJWE Content Encryption Key.

Returns

this

Deprecated

You should not use this method. It is only really intended for test and vector validation purposes.


setInitializationVector()

â–¸ 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.

Parameters

ParameterTypeDescription
ivUint8ArrayJWE Initialization Vector.

Returns

this

Deprecated

You should not use this method. It is only really intended for test and vector validation purposes.


setKeyManagementParameters()

â–¸ setKeyManagementParameters(parameters): this

Sets the JWE Key Management parameters to be used when encrypting. Use this method instead of the header setters to configure algorithm inputs such as ECDH-ES "apu" (Agreement PartyUInfo) and "apv" (Agreement PartyVInfo), or PBES2 "p2c" (PBES2 Count). The parameters are added to the appropriate JOSE Header.

Parameters

ParameterTypeDescription
parametersJWEKeyManagementHeaderParametersJWE Key Management parameters.

Returns

this


setProtectedHeader()

â–¸ setProtectedHeader(protectedHeader): this

Sets the JWE Protected Header on the FlattenedEncrypt object.

Parameters

ParameterTypeDescription
protectedHeaderJWEHeaderParametersJWE Protected Header.

Returns

this


setSharedUnprotectedHeader()

â–¸ setSharedUnprotectedHeader(sharedUnprotectedHeader): this

Sets the JWE Shared Unprotected Header on the FlattenedEncrypt object.

Parameters

ParameterTypeDescription
sharedUnprotectedHeaderJWEHeaderParametersJWE Shared Unprotected Header.

Returns

this


setUnprotectedHeader()

â–¸ setUnprotectedHeader(unprotectedHeader): this

Sets the JWE Per-Recipient Unprotected Header on the FlattenedEncrypt object.

Parameters

ParameterTypeDescription
unprotectedHeaderJWEHeaderParametersJWE Per-Recipient Unprotected Header.

Returns

this