Skip to content

Latest commit

 

History

History
156 lines (93 loc) · 4.91 KB

jwe_compact_encrypt.CompactEncrypt.md

File metadata and controls

156 lines (93 loc) · 4.91 KB

Class: CompactEncrypt

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.

Example

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)

Table of contents

Constructors

Methods

Constructors

constructor

new CompactEncrypt(plaintext): CompactEncrypt

Parameters

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

Returns

CompactEncrypt

Methods

encrypt

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

Encrypts and resolves the value of the Compact JWE string.

Parameters

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

Returns

Promise<string>


setContentEncryptionKey

setContentEncryptionKey(cek): CompactEncrypt

Sets a content encryption key to use, by default a random suitable one is generated for the JWE enc" (Encryption Algorithm) Header Parameter.

Parameters

Name Type Description
cek Uint8Array JWE Content Encryption Key.

Returns

CompactEncrypt

Deprecated

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


setInitializationVector

setInitializationVector(iv): CompactEncrypt

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

Name Type Description
iv Uint8Array JWE Initialization Vector.

Returns

CompactEncrypt

Deprecated

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


setKeyManagementParameters

setKeyManagementParameters(parameters): CompactEncrypt

Sets the JWE Key Management parameters to be used when encrypting the Content Encryption Key. You do not need to invoke this method, it is only really intended for test and vector validation purposes.

Parameters

Name Type Description
parameters JWEKeyManagementHeaderParameters JWE Key Management parameters.

Returns

CompactEncrypt


setProtectedHeader

setProtectedHeader(protectedHeader): CompactEncrypt

Sets the JWE Protected Header on the CompactEncrypt object.

Parameters

Name Type Description
protectedHeader CompactJWEHeaderParameters JWE Protected Header object.

Returns

CompactEncrypt