1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
# Class: GeneralEncrypt
[💗 Help the project](https://github.com/sponsors/panva)
The GeneralEncrypt class is a utility for creating General JWE objects.
**`example`** Usage
```js
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
- [constructor](jwe_general_encrypt.GeneralEncrypt.md#constructor)
### Methods
- [addRecipient](jwe_general_encrypt.GeneralEncrypt.md#addrecipient)
- [encrypt](jwe_general_encrypt.GeneralEncrypt.md#encrypt)
- [setAdditionalAuthenticatedData](jwe_general_encrypt.GeneralEncrypt.md#setadditionalauthenticateddata)
- [setProtectedHeader](jwe_general_encrypt.GeneralEncrypt.md#setprotectedheader)
- [setSharedUnprotectedHeader](jwe_general_encrypt.GeneralEncrypt.md#setsharedunprotectedheader)
## Constructors
### constructor
• **new GeneralEncrypt**(`plaintext`)
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `plaintext` | `Uint8Array` | Binary representation of the plaintext to encrypt. |
## Methods
### addRecipient
â–¸ **addRecipient**(`key`, `options?`): [`Recipient`](../interfaces/jwe_general_encrypt.Recipient.md)
Adds an additional recipient for the General JWE object.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `key` | `Uint8Array` \| [`KeyLike`](../types/types.KeyLike.md) | Public Key or Secret to encrypt the Content Encryption Key for the recipient with. |
| `options?` | [`CritOption`](../interfaces/types.CritOption.md) | JWE Encryption options. |
#### Returns
[`Recipient`](../interfaces/jwe_general_encrypt.Recipient.md)
___
### encrypt
â–¸ **encrypt**(`options?`): `Promise`<[`GeneralJWE`](../interfaces/types.GeneralJWE.md)\>
Encrypts and resolves the value of the General JWE object.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `options?` | [`DeflateOption`](../interfaces/types.DeflateOption.md) | JWE Encryption options. |
#### Returns
`Promise`<[`GeneralJWE`](../interfaces/types.GeneralJWE.md)\>
___
### setAdditionalAuthenticatedData
â–¸ **setAdditionalAuthenticatedData**(`aad`): [`GeneralEncrypt`](jwe_general_encrypt.GeneralEncrypt.md)
Sets the Additional Authenticated Data on the GeneralEncrypt object.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `aad` | `Uint8Array` | Additional Authenticated Data. |
#### Returns
[`GeneralEncrypt`](jwe_general_encrypt.GeneralEncrypt.md)
___
### setProtectedHeader
â–¸ **setProtectedHeader**(`protectedHeader`): [`GeneralEncrypt`](jwe_general_encrypt.GeneralEncrypt.md)
Sets the JWE Protected Header on the GeneralEncrypt object.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `protectedHeader` | [`JWEHeaderParameters`](../interfaces/types.JWEHeaderParameters.md) | JWE Protected Header object. |
#### Returns
[`GeneralEncrypt`](jwe_general_encrypt.GeneralEncrypt.md)
___
### setSharedUnprotectedHeader
â–¸ **setSharedUnprotectedHeader**(`sharedUnprotectedHeader`): [`GeneralEncrypt`](jwe_general_encrypt.GeneralEncrypt.md)
Sets the JWE Shared Unprotected Header on the GeneralEncrypt object.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `sharedUnprotectedHeader` | [`JWEHeaderParameters`](../interfaces/types.JWEHeaderParameters.md) | JWE Shared Unprotected Header object. |
#### Returns
[`GeneralEncrypt`](jwe_general_encrypt.GeneralEncrypt.md)
|