Back to Jose

Class: FlattenedEncrypt

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

6.2.125.2 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.

Builds and encrypts 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

Creates a Flattened JWE encryptor.

Parameters

ParameterTypeDescription
plaintextUint8ArrayBinary representation of the plaintext to encrypt.

Returns

FlattenedEncrypt

Methods

encrypt()

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

Encrypts the plaintext as a Flattened JWE.

Parameters

ParameterTypeDescription
keyKeyInputPublic key or shared secret. See Algorithm Key Requirements.
options?EncryptOptionsJWE Encryption options.

Returns

Promise<FlattenedJWE>


setAdditionalAuthenticatedData()

â–¸ setAdditionalAuthenticatedData(aad): this

Sets additional data to authenticate without encrypting it.

Parameters

ParameterTypeDescription
aadUint8ArrayAdditional Authenticated Data.

Returns

this


setContentEncryptionKey()

â–¸ setContentEncryptionKey(cek): this

Sets a content encryption key instead of generating a random one for the JWE "enc" algorithm. May only be called once.

Parameters

ParameterTypeDescription
cekUint8ArrayJWE Content Encryption Key.

Returns

this

Deprecated

Use only for testing and vector validation.


setInitializationVector()

â–¸ setInitializationVector(iv): this

Sets the content encryption IV instead of generating a random one for the JWE "enc" algorithm. May only be called once.

Parameters

ParameterTypeDescription
ivUint8ArrayJWE Initialization Vector.

Returns

this

Deprecated

Use only for testing and vector validation.


setKeyManagementParameters()

â–¸ setKeyManagementParameters(parameters): this

Sets key management inputs such as ECDH-ES "apu"/"apv" or PBES2 "p2c". Use this method instead of header setters; the resulting parameters are added to the JOSE header. May only be called once.

Parameters

ParameterTypeDescription
parametersJWEKeyManagementHeaderParametersJWE Key Management parameters.

Returns

this


setProtectedHeader()

â–¸ setProtectedHeader(protectedHeader): this

Sets the JWE Protected Header. May only be called once.

Parameters

ParameterTypeDescription
protectedHeaderJWEHeaderParametersJWE Protected Header.

Returns

this


setSharedUnprotectedHeader()

â–¸ setSharedUnprotectedHeader(sharedUnprotectedHeader): this

Sets the JWE Shared Unprotected Header. May only be called once.

Parameters

ParameterTypeDescription
sharedUnprotectedHeaderJWEHeaderParametersJWE Shared Unprotected Header.

Returns

this


setUnprotectedHeader()

â–¸ setUnprotectedHeader(unprotectedHeader): this

Sets the JWE Per-Recipient Unprotected Header. May only be called once.

Parameters

ParameterTypeDescription
unprotectedHeaderJWEHeaderParametersJWE Per-Recipient Unprotected Header.

Returns

this