mirror of
https://github.com/danbulant/jose
synced 2026-05-19 12:29:04 +00:00
3.6 KiB
3.6 KiB
Class: GeneralEncrypt
The GeneralEncrypt class is a utility for creating General JWE objects.
example Usage
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)
Table of contents
Constructors
Methods
Constructors
constructor
• new GeneralEncrypt(plaintext)
Parameters
| Name | Type | Description |
|---|---|---|
plaintext |
Uint8Array |
Binary representation of the plaintext to encrypt. |
Methods
addRecipient
▸ addRecipient(key, options?): Recipient
Adds an additional recipient for the General JWE object.
Parameters
| Name | Type | Description |
|---|---|---|
key |
KeyLike | Uint8Array |
Public Key or Secret to encrypt the Content Encryption Key for the recipient with. |
options? |
CritOption |
JWE Encryption options. |
Returns
encrypt
▸ encrypt(options?): Promise<GeneralJWE>
Encrypts and resolves the value of the General JWE object.
Parameters
| Name | Type | Description |
|---|---|---|
options? |
DeflateOption |
JWE Encryption options. |
Returns
Promise<GeneralJWE>
setAdditionalAuthenticatedData
▸ setAdditionalAuthenticatedData(aad): GeneralEncrypt
Sets the Additional Authenticated Data on the GeneralEncrypt object.
Parameters
| Name | Type | Description |
|---|---|---|
aad |
Uint8Array |
Additional Authenticated Data. |
Returns
setProtectedHeader
▸ setProtectedHeader(protectedHeader): GeneralEncrypt
Sets the JWE Protected Header on the GeneralEncrypt object.
Parameters
| Name | Type | Description |
|---|---|---|
protectedHeader |
JWEHeaderParameters |
JWE Protected Header object. |
Returns
setSharedUnprotectedHeader
▸ setSharedUnprotectedHeader(sharedUnprotectedHeader): GeneralEncrypt
Sets the JWE Shared Unprotected Header on the GeneralEncrypt object.
Parameters
| Name | Type | Description |
|---|---|---|
sharedUnprotectedHeader |
JWEHeaderParameters |
JWE Shared Unprotected Header object. |