Skip to content

Latest commit

 

History

History
201 lines (124 loc) · 5.94 KB

jwe_flattened_encrypt.FlattenedEncrypt.md

File metadata and controls

201 lines (124 loc) · 5.94 KB

Class: FlattenedEncrypt

The FlattenedEncrypt class is a utility for creating Flattened JWE objects.

example Usage

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(encoder.encode('The Fellowship of the Ring'))
  .encrypt(publicKey)

console.log(jwe)

Table of contents

Constructors

Methods

Constructors

constructor

new FlattenedEncrypt(plaintext)

Parameters

Name Type Description
plaintext Uint8Array Binary representation of the plaintext to encrypt.

Methods

encrypt

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

Encrypts and resolves the value of the Flattened JWE object.

Parameters

Name Type Description
key KeyLike | Uint8Array Public Key or Secret to encrypt the JWE with.
options? EncryptOptions JWE Encryption options.

Returns

Promise<FlattenedJWE>


setAdditionalAuthenticatedData

setAdditionalAuthenticatedData(aad): FlattenedEncrypt

Sets the Additional Authenticated Data on the FlattenedEncrypt object.

Parameters

Name Type Description
aad Uint8Array Additional Authenticated Data.

Returns

FlattenedEncrypt


setContentEncryptionKey

setContentEncryptionKey(cek): FlattenedEncrypt

Sets a content encryption key to use, by default a random suitable one is generated for the JWE enc" (Encryption Algorithm) Header Parameter. You do not need to invoke this method, it is only really intended for test and vector validation purposes.

Parameters

Name Type Description
cek Uint8Array JWE Content Encryption Key.

Returns

FlattenedEncrypt


setInitializationVector

setInitializationVector(iv): FlattenedEncrypt

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. You do not need to invoke this method, it is only really intended for test and vector validation purposes.

Parameters

Name Type Description
iv Uint8Array JWE Initialization Vector.

Returns

FlattenedEncrypt


setKeyManagementParameters

setKeyManagementParameters(parameters): FlattenedEncrypt

Sets the JWE Key Management parameters to be used when encrypting. Use of this is method is really only needed for ECDH-ES based algorithms when utilizing the Agreement PartyUInfo or Agreement PartyVInfo parameters. Other parameters will always be randomly generated when needed and missing.

Parameters

Name Type Description
parameters JWEKeyManagementHeaderParameters JWE Key Management parameters.

Returns

FlattenedEncrypt


setProtectedHeader

setProtectedHeader(protectedHeader): FlattenedEncrypt

Sets the JWE Protected Header on the FlattenedEncrypt object.

Parameters

Name Type Description
protectedHeader JWEHeaderParameters JWE Protected Header.

Returns

FlattenedEncrypt


setSharedUnprotectedHeader

setSharedUnprotectedHeader(sharedUnprotectedHeader): FlattenedEncrypt

Sets the JWE Shared Unprotected Header on the FlattenedEncrypt object.

Parameters

Name Type Description
sharedUnprotectedHeader JWEHeaderParameters JWE Shared Unprotected Header.

Returns

FlattenedEncrypt


setUnprotectedHeader

setUnprotectedHeader(unprotectedHeader): FlattenedEncrypt

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

Parameters

Name Type Description
unprotectedHeader JWEHeaderParameters JWE Per-Recipient Unprotected Header.

Returns

FlattenedEncrypt