nestjs-cryptography 2.2.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +147 -0
  2. package/dist/cryptography.service.d.ts +21 -23
  3. package/dist/cryptography.service.js +82 -82
  4. package/dist/interfaces/cryptography-options.interface.d.ts +1 -1
  5. package/dist/interfaces/generic-options.interface.d.ts +5 -0
  6. package/dist/interfaces/generic-options.interface.js +2 -0
  7. package/dist/interfaces/index.d.ts +1 -0
  8. package/dist/interfaces/index.js +1 -0
  9. package/package.json +16 -15
  10. package/wiki/README.md +41 -0
  11. package/wiki/babel.config.js +3 -0
  12. package/wiki/docs/Internals/_category_.json +7 -0
  13. package/wiki/docs/Internals/create-safe-random-data.mdx +41 -0
  14. package/wiki/docs/Internals/create-secure-hmac.mdx +31 -0
  15. package/wiki/docs/Internals/symmetric-data-encrypt.mdx +103 -0
  16. package/wiki/docs/Internals/symmetric-secure-data-encrypt.mdx +161 -0
  17. package/wiki/docs/api-reference/_category_.json +7 -0
  18. package/wiki/docs/api-reference/settings.mdx +199 -0
  19. package/wiki/docs/guides/_category_.json +7 -0
  20. package/wiki/docs/guides/generics.mdx +170 -0
  21. package/wiki/docs/guides/hashing.mdx +258 -0
  22. package/wiki/docs/guides/hmac.mdx +271 -0
  23. package/wiki/docs/guides/key-derivation.mdx +101 -0
  24. package/wiki/docs/guides/password-hashing.mdx +136 -0
  25. package/wiki/docs/guides/symmetric-encryption.mdx +272 -0
  26. package/wiki/docs/intro.mdx +148 -0
  27. package/wiki/docusaurus.config.ts +138 -0
  28. package/wiki/package.json +48 -0
  29. package/wiki/sidebars.ts +20 -0
  30. package/wiki/src/common/timing-attack.mdx +3 -0
  31. package/wiki/src/common/tips.mdx +18 -0
  32. package/wiki/src/components/GenerateHexButton/index.tsx +35 -0
  33. package/wiki/src/components/GenerateHexButton/styles.module.css +10 -0
  34. package/wiki/src/components/GenericLabel/index.tsx +19 -0
  35. package/wiki/src/components/HomepageFeatures/index.tsx +70 -0
  36. package/wiki/src/components/HomepageFeatures/styles.module.css +11 -0
  37. package/wiki/src/components/RecommendedLabel/index.tsx +19 -0
  38. package/wiki/src/components/RequiredLabel/index.tsx +12 -0
  39. package/wiki/src/css/custom.css +30 -0
  40. package/wiki/src/pages/index.module.css +23 -0
  41. package/wiki/src/pages/index.tsx +43 -0
  42. package/wiki/src/pages/markdown-page.md +7 -0
  43. package/wiki/static/.nojekyll +0 -0
  44. package/wiki/static/img/gear_api.png +0 -0
  45. package/wiki/static/img/logo.svg +1 -0
  46. package/wiki/static/img/nestjs_favicon.ico +0 -0
  47. package/wiki/static/img/node_crypto.png +0 -0
  48. package/wiki/static/img/phc_logo.png +0 -0
  49. package/wiki/static/img/profile.png +0 -0
  50. package/wiki/versioned_docs/version-2.x/Internals/_category_.json +8 -0
  51. package/wiki/versioned_docs/version-2.x/Internals/create-secure-hmac.mdx +30 -0
  52. package/wiki/versioned_docs/version-2.x/Internals/symmetric-secure-data-encrypt.mdx +160 -0
  53. package/wiki/versioned_docs/version-2.x/api-reference/_category_.json +8 -0
  54. package/wiki/versioned_docs/version-2.x/api-reference/settings.mdx +197 -0
  55. package/wiki/versioned_docs/version-2.x/guides/_category_.json +7 -0
  56. package/wiki/versioned_docs/version-2.x/guides/generics.mdx +133 -0
  57. package/wiki/versioned_docs/version-2.x/guides/hashing.mdx +229 -0
  58. package/wiki/versioned_docs/version-2.x/guides/hmac.mdx +198 -0
  59. package/wiki/versioned_docs/version-2.x/guides/key-derivation.mdx +98 -0
  60. package/wiki/versioned_docs/version-2.x/guides/password-hashing.mdx +132 -0
  61. package/wiki/versioned_docs/version-2.x/guides/symmetric-encryption.mdx +107 -0
  62. package/wiki/versioned_docs/version-2.x/intro.mdx +148 -0
  63. package/wiki/versioned_sidebars/version-2.x-sidebars.json +8 -0
  64. package/wiki/versions.json +3 -0
@@ -0,0 +1,160 @@
1
+ ---
2
+ title: Symmetric Secure Data Encrypt
3
+ sidebar_label: Symmetric Secure Data Encrypt
4
+ sidebar_position: 2
5
+ ---
6
+
7
+ In the following section, you will see a diagram of the cryptographic operations performed when calling the method [`symmetricSecureDataEncrypt`][1]
8
+
9
+ This method securely encrypts input data by first generating a random 32-byte Data Encryption Key (DEK)
10
+ using a cryptographically secure method. It then encrypts the data using AES-256-GCM with the DEK,
11
+ producing an output that includes the initialization vector (IV), salt, authentication tag, and ciphertext.
12
+ After encrypting the data, the method also encrypts the DEK itself using a master key, and finally,
13
+ it concatenates the encrypted DEK and the encrypted data, returning the complete encrypted result for secure storage or transmission.
14
+
15
+ ## **Diagram**
16
+
17
+ <div style={{ textAlign: 'center' }}>
18
+ ```mermaid
19
+ graph TD
20
+ A[Input: Data] --> ID
21
+
22
+ DEK{Generate DEK} --> SG1
23
+
24
+ subgraph SG1[Generate DEK]
25
+ SG1A1[Generate 64 bytes of random data] --> SG1A1A2[Create Secret Key from random data]
26
+ SG1A1A2 --> SG1A1A3[Generate another 64 bytes of random data]
27
+ SG1A1A3 --> SG1A1A4[Use HKDF with sha3-256 to derive IV]
28
+ end
29
+
30
+
31
+ subgraph ED[Encrypt Data]
32
+ SG1A1A4 --> DEK1[DEK]
33
+
34
+ ID(DATA)
35
+
36
+ IV1[IV] --> IV1A1{Generate IV}
37
+ SALT1[SALT] --> SALT1A1{Generate SALT}
38
+
39
+ IV1A1 --> SGIV1
40
+ SALT1A1 --> SGSALT1
41
+
42
+ subgraph SGIV1["Generate IV (12 bytes)"]
43
+ SGIV1A1[Generate 64 bytes of random data] --> SGIV1A1A2[Create Secret Key from random data]
44
+ SGIV1A1A2 --> SGIV1A1A3[Generate another 64 bytes of random data]
45
+ SGIV1A1A3 --> SGIV1A1A4[Use HKDF with sha3-256 to derive IV]
46
+ end
47
+
48
+ subgraph SGSALT1["Generate Salt (64 bytes)"]
49
+ SGSSALT1A1[Generate 64 bytes of random data] --> SGSSALT1A1A2[Create Secret Key from random data]
50
+ SGSSALT1A1A2 --> SGSSALT1A1A3[Generate another 64 bytes of random data]
51
+ SGSSALT1A1A3 --> SGSSALT1A1A4[Use HKDF with sha3-256 to derive SALT]
52
+ end
53
+
54
+ DEK1 --> DERIVEDEK[Securely derive DEK using Argon2 + Salt]
55
+ DERIVEDEK --> EK1(Encryption Key)
56
+ SGSSALT1A1A4 --> DERIVEDEK
57
+
58
+ SGIV1A1A4 --> FIV1(IV)
59
+ FIV1 ==> FED{Encrypt Data using AES-256-GCM with Encryption Key + IV}
60
+ EK1 ==> FED
61
+ ID ==> FED
62
+
63
+ FED -.- FFED["Encrypted Data [IV + Salt + AuthTag + CipherText]"]
64
+ end
65
+
66
+
67
+ subgraph EDEK[Encrypt DEK]
68
+ SG1A1A4 --> DEK2(DEK)
69
+
70
+ IV2[IV] --> IV2A1{Generate IV}
71
+ SALT2[SALT] --> SALT2A1{Generate SALT}
72
+
73
+ IV2A1 --> SGIV2
74
+ SALT2A1 --> SGSALT2
75
+
76
+ subgraph SGIV2["Generate IV (12 bytes)"]
77
+ SGIV2A1[Generate 64 bytes of random data] --> SGIV2A1A2[Create Secret Key from random data]
78
+ SGIV2A1A2 --> SGIV2A1A3[Generate another 64 bytes of random data]
79
+ SGIV2A1A3 --> SGIV2A1A4[Use HKDF with sha3-256 to derive IV]
80
+ end
81
+
82
+ subgraph SGSALT2["Generate Salt (64 bytes)"]
83
+ SGSSALT2A1[Generate 64 bytes of random data] --> SGSSALT2A1A2[Create Secret Key from random data]
84
+ SGSSALT2A1A2 --> SGSSALT2A1A3[Generate another 64 bytes of random data]
85
+ SGSSALT2A1A3 --> SGSSALT2A1A4[Use HKDF with sha3-256 to derive SALT]
86
+ end
87
+
88
+ MK[MASTER KEY] --> DERIVEMK[Securely derive Master Key using Argon2 + Salt]
89
+ DERIVEMK --> EK2(Encryption Key)
90
+ SGSSALT2A1A4 --> DERIVEMK
91
+
92
+ SGIV2A1A4 --> FIV2(IV)
93
+
94
+ EK2 ==> FEDEK{Encrypt DEK using AES-256-GCM with Encryption Key + IV}
95
+ DEK2 ==> FEDEK
96
+ FIV2 ==> FEDEK
97
+
98
+ FEDEK -.- FFEDEK["Encrypted DEK [IV + Salt + AuthTag + CipherText]"]
99
+ end
100
+
101
+ FFEDEK -.-> FFDD(["Concatenate Encrypted DEK + Encrypted Data"])
102
+ FFED -.-> FFDD
103
+
104
+
105
+ %% -----------------
106
+
107
+ A:::inputDataStyle
108
+
109
+ MK:::masterKeyStyle
110
+
111
+ DEK:::dekStyle
112
+
113
+ SALT1A1:::saltStyle
114
+ SALT2A1:::saltStyle
115
+
116
+ IV1A1:::ivStyle
117
+ IV2A1:::ivStyle
118
+
119
+ FEDEK:::encryptionStyle
120
+ FED:::encryptionStyle
121
+
122
+ FFEDEK:::resultStyle
123
+ FFED:::resultStyle
124
+
125
+ FFDD:::finalResultStyle
126
+
127
+ %% Style definitions
128
+ classDef inputDataStyle fill:#00ff00,stroke:#333,stroke-width:2px;
129
+ classDef masterKeyStyle fill:#ff0000,stroke:#333,stroke-width:2px;
130
+ classDef dekStyle fill:#BCD3A3,stroke:#333,stroke-width:2px;
131
+ classDef ivStyle fill:#ffcc00,stroke:#333,stroke-width:2px;
132
+ classDef saltStyle fill:#ff6666,stroke:#333,stroke-width:2px;
133
+ classDef deriveKeyStyle fill:#66ccff,stroke:#333,stroke-width:2px;
134
+ classDef secureKeyStyle fill:#66ff66,stroke:#333,stroke-width:2px;
135
+ classDef encryptionStyle fill:#cc99ff,stroke:#333,stroke-width:2px;
136
+ classDef resultStyle fill:#ff9966,stroke:#333,stroke-width:2px;
137
+ classDef finalResultStyle fill:#66ffcc,stroke:#333,stroke-width:2px;
138
+ ```
139
+ </div>
140
+
141
+
142
+ ## **Explanation of the Diagram**
143
+ 1) Generate DEK:
144
+ - The internal `createSaferRandomData` method generates a 32-byte **DEK** (Data Encryption Key) using `HKDF(sha3-256 + random_key + random_salt)`.
145
+ 2) Encrypt the Input Data:
146
+ - **Generate IV (12 bytes)**: A 12-byte IV is generated using `HKDF(sha3-256 + random_key + random_salt)`.
147
+ - **Generate Salt (64 bytes)**: A 64-byte salt is generated, also using `HKDF(sha3-256 + random_key + random_salt)`.
148
+ - **Derive Secure Encryption Key**: A secure encryption key is derived using **Argon2** with the DEK and salt.
149
+ - **Encrypt Data**: The input data is encrypted using **AES-256-GCM** with the derived secure encryption key, producing the encrypted result: _IV + Salt + AuthTag + CipherText_.
150
+ 3) Encrypt the DEK:
151
+ - The DEK itself is encrypted using the master key:
152
+ - **Generate IV (12 bytes)**: A 12-byte IV is generated using `HKDF(sha3-256 + random_key + random_salt)`.
153
+ - **Generate Salt (64 bytes)**: A 64-byte salt is generated, also using `HKDF(sha3-256 + random_key + random_salt)`.
154
+ - **Derive Master Key**: A secure encryption key is derived using **Argon2** with the [**MasterKey**][2] and salt.
155
+ - **Encrypt DEK**: The DEK is encrypted using AES-256-GCM, resulting in the encrypted DEK: _IV + Salt + AuthTag + CipherText_.
156
+ 4) Concatenate and Return:
157
+ - The encrypted DEK and the encrypted input data are concatenated to form the final output, which is then returned.
158
+
159
+ [1]: ../guides/symmetric-encryption#symmetricsecuredataencrypt
160
+ [2]: ../api-reference/settings#masterkey-1
@@ -0,0 +1,8 @@
1
+ {
2
+ "label": "API Reference",
3
+ "position": 2,
4
+ "link": {
5
+ "type": "generated-index",
6
+ "description": "5 minutes to learn the most important Docusaurus concepts."
7
+ }
8
+ }
@@ -0,0 +1,197 @@
1
+ ---
2
+ title: Configuration Options
3
+ sidebar_label: Configuration Options
4
+ sidebar_position: 1
5
+ ---
6
+
7
+ import Tabs from '@theme/Tabs';
8
+ import TabItem from '@theme/TabItem';
9
+ import GenerateHexButton from '@site/src/components/GenerateHexButton';
10
+
11
+ <details>
12
+ <summary>👨‍🔧 Let me help you a bit....</summary>
13
+
14
+ <div>
15
+
16
+ :::info
17
+
18
+ If at any point you need to securely generate a secret key for the following configuration, you can do so as follows.
19
+
20
+ <Tabs
21
+ defaultValue="linux"
22
+ values={[
23
+ { label: 'Linux / macOS', value: 'linux', },
24
+ { label: 'Windows / Others', value: 'windows', }
25
+ ]
26
+ }>
27
+ <TabItem value="linux">
28
+ Type this on the terminal:
29
+ ```bash
30
+ openssl rand -hex 32
31
+ ```
32
+ </TabItem>
33
+ <TabItem value="windows">
34
+ <GenerateHexButton />
35
+ </TabItem>
36
+ </Tabs>
37
+
38
+
39
+ :::
40
+
41
+ </div>
42
+ </details>
43
+
44
+ <details>
45
+ <summary>Example Usage</summary>
46
+
47
+ <div>
48
+
49
+ ```typescript title="app.module.ts"
50
+ import { Module } from '@nestjs/common';
51
+ import * as argon2 from 'argon2';
52
+ import {
53
+ CryptographyModule,
54
+ CryptographyOptionsInterface,
55
+ } from 'nestjs-cryptography';
56
+
57
+ @Module({
58
+ imports: [
59
+ CryptographyModule.registerAsync({
60
+ imports: [ConfigModule],
61
+ isGlobal: true,
62
+ useFactory: (configService: ConfigService) =>
63
+ ({
64
+ isGlobal: true,
65
+ kdf: {
66
+ timeCost: 32,
67
+ memoryCost: 131072,
68
+ argon2Type: argon2.argon2i,
69
+ defaultOutputKeyLength: 32,
70
+ },
71
+ hashing: {
72
+ password: {
73
+ timeCost: 10,
74
+ memoryCost: 65536,
75
+ argon2Type: argon2.argon2id,
76
+ outputKeyLength: 64,
77
+ },
78
+ hmac: {
79
+ // ‼️ change me please ‼️
80
+ masterKey: '6c0504d3836ab96a25daeb61c44f6d6345d99a746f6a776290c48d9a5ba8b124',
81
+ },
82
+ },
83
+ encryption: {
84
+ symmetric: {
85
+ // ‼️ change me please ‼️
86
+ masterKey: '1538755db39d3d98115af5be688b1486673910f7d2630fc48dd27c1a1ace2631',
87
+ },
88
+ },
89
+ }) as CryptographyOptionsInterface,
90
+ inject: [ConfigService],
91
+ }),
92
+ ],
93
+ export class AppModule {}
94
+ ```
95
+
96
+ </div>
97
+ </details>
98
+
99
+ ## `kdf`
100
+
101
+ Settings for the Key Derivation Function.
102
+
103
+ - ### <u>defaultOutputKeyLength</u>
104
+ > `type: number` | **required**
105
+
106
+ The default length (in bytes) of the derived key.
107
+
108
+ - ### <u>argon2Type</u>
109
+ > `type: Argon2Type` | **required**
110
+
111
+ The variant of the Argon2 algorithm to use (Argon2d, Argon2i, or Argon2id)
112
+
113
+ - ### <u>memoryCost</u>
114
+ > `type: number` | **required**
115
+
116
+ Memory usage (in kilobytes) for the algorithm.
117
+
118
+ - ### <u>timeCost</u>
119
+ > `type: number` | **required**
120
+
121
+ Number of iterations to perform.
122
+
123
+ ---
124
+
125
+ ## `hashing`
126
+
127
+ Settings for hashing operations.
128
+
129
+ ### `password`
130
+
131
+ Configuration for password hashing.
132
+
133
+ - ### <u>outputKeyLength</u>
134
+ > `type: number` | **required**
135
+
136
+ The default length (in bytes) of the derived key.
137
+
138
+ - ### <u>argon2Type</u>
139
+ > `type: Argon2Type` | **required**
140
+
141
+ The variant of the Argon2 algorithm to use (Argon2d, Argon2i, or Argon2id)
142
+
143
+ - ### <u>memoryCost</u>
144
+ > `type: number` | **required**
145
+
146
+ Memory usage (in kilobytes) for the algorithm.
147
+
148
+ - ### <u>timeCost</u>
149
+ > `type: number` | **required**
150
+
151
+ Number of iterations to perform.
152
+
153
+ ### `hmac`
154
+
155
+ Configuration for HMAC (Hash-Based Message Authentication Code).
156
+
157
+ - ### <u>masterKey</u>
158
+ > `type: string` | **required**
159
+
160
+ The secret key used for generating HMACs.
161
+
162
+ ---
163
+
164
+ ## `encryption`
165
+
166
+ Settings for encryption operations.
167
+
168
+ ### `symmetric`
169
+
170
+ Configuration for symmetric encryption.
171
+
172
+ - ### <u>masterKey</u>
173
+ > `type: string` | **required**
174
+
175
+ The secret key used for encryption and decryption.
176
+
177
+ :::danger
178
+
179
+ Note: Always ensure that secret keys are generated securely and stored safely.
180
+ Do not hard-code them into your source files or expose them in version control systems.
181
+
182
+ :::
183
+
184
+ ## Additional Information
185
+
186
+ - **Argon2Type**: An enumeration defining the type of Argon2 algorithm to use.
187
+ The options typically include `Argon2d`, `Argon2i`, and `Argon2id`.
188
+ [Choose the one that best fits your security requirements][3].
189
+
190
+ - **Security Considerations**: Adjust `memoryCost` and `timeCost`
191
+ according to the desired balance between performance and security.
192
+ Higher values increase security but require more resources.
193
+ You could se more information on [owasp][1] or the [official specs][2]
194
+
195
+ [1]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#argon2id
196
+ [2]: https://www.password-hashing.net/argon2-specs.pdf#page=15
197
+ [3]: https://en.wikipedia.org/wiki/Argon2
@@ -0,0 +1,7 @@
1
+ {
2
+ "label": "Guides",
3
+ "position": 3,
4
+ "link": {
5
+ "type": "generated-index"
6
+ }
7
+ }
@@ -0,0 +1,133 @@
1
+ ---
2
+ title: Generics
3
+ sidebar_label: Generics
4
+ sidebar_position: 1
5
+ description: Methods to perform typical operations UUID, randomPassword, ...
6
+ ---
7
+
8
+ import RequiredLabel from '@site/src/components/RequiredLabel';
9
+ import Tips from '@site/src/common/tips.mdx'
10
+
11
+ This section contains some generic methods to perform typical operations
12
+
13
+ ## Generate an UUIDv4
14
+
15
+ Method to generate a UUID version 4.
16
+
17
+ ### `genUUID`
18
+
19
+ ```tsx
20
+ public genUUID (
21
+ secure = false
22
+ ): string;
23
+ ```
24
+
25
+ **Parameters:**
26
+
27
+ | Name | Type | Default | Description |
28
+ |-------------------------|---------|---------|------------------------------------------------------|
29
+ | secure <RequiredLabel/> | boolean | false | Decide to use a more secure generation using entropy |
30
+
31
+
32
+ **Outputs:**
33
+
34
+ As output, it will return a string of this format `0E928AD4-4D11-4C7C-A83A-8DD7361FFC01`
35
+
36
+
37
+ **Usage:**
38
+ ```typescript
39
+ async someAwesomeMethod(): Promise<string> {
40
+ const newUUID = this.cryptographyService.genUUID(true);
41
+ ...
42
+ return newUUID;
43
+ }
44
+ ```
45
+
46
+ ## Generate random password
47
+
48
+ Method to generate a random password with this set of characters:
49
+ `a-z 0-9` if _**hex**_ used, or `A-Z a-z 0-9 + = /` if _**base64**_ used.
50
+
51
+ ### `genRandomPassword`
52
+
53
+ ```tsx
54
+ public genRandomPassword (
55
+ length: number,
56
+ encoding: 'base64' | 'hex'
57
+ ): string;
58
+ ```
59
+
60
+ **Parameters:**
61
+
62
+ | Name | Type | Default | Description |
63
+ |---------------------------|---------------|---------|--------------------------------------------------|
64
+ | length <RequiredLabel/> | number | | The password output length |
65
+ | encoding <RequiredLabel/> | base64 \| hex | | The password output format hexadecimal or base64 |
66
+
67
+
68
+ **Outputs:**
69
+
70
+ As output, it will return a string of this format:
71
+ - base64: `jh2EducrV7yH8tGAc8Jkdcso`
72
+ - hex: `b4da8e4aba39c9f70dde717d`
73
+
74
+ **Usage:**
75
+ ```typescript
76
+ async createUserPassword(): Promise<string> {
77
+ const newPassword = this.cryptographyService.genRandomPassword(24, 'base64');
78
+ ...
79
+ return newPassword;
80
+ }
81
+ ```
82
+
83
+ ## Generate symmetric key
84
+
85
+ Method to generate a cryptographically secure SymmetricKey in [KeyObject][1] format
86
+ to use in subsequent encryption/decryption operations.
87
+
88
+ ### `generateSymmetricKey`
89
+
90
+ ```tsx
91
+ public generateSymmetricKey (
92
+ length: number = 256
93
+ ): KeyObject;
94
+ ```
95
+
96
+ **Parameters:**
97
+
98
+ | Name | Type | Default | Description |
99
+ |--------|--------|---------|---------------------------------|
100
+ | length | number | 256 | The symmetric key output length |
101
+
102
+
103
+ **Outputs:**
104
+
105
+ As output, it will return an object of type [KeyObject][1].
106
+
107
+ :::info
108
+ If you want to export this KeyObject to different types, you can access the `.export` [method][2]
109
+ :::
110
+
111
+ **Usage:**
112
+ ```typescript
113
+ async createSymmetricKey(): Promise<void> {
114
+ const new32KeySize = this.cryptographyService.generateSymmetricKey(32);
115
+ console.log(new32KeySize.export().toString('hex')); // f32.....4ee
116
+
117
+ const aes128KeySize = this.cryptographyService.generateSymmetricKey(128);
118
+ console.log(aes128KeySize.export().toString('hex')); // e89.....41e
119
+
120
+ const aes192KeySize = this.cryptographyService.generateSymmetricKey(192);
121
+ console.log(aes192KeySize.export().toString('base64')); // 8OI.....ZQ=
122
+
123
+ const aes256KeySize = this.cryptographyService.generateSymmetricKey(256);
124
+ console.log(aes256KeySize.export()); // <Buffer cc 2b.....cd a1 08>
125
+ }
126
+ ```
127
+
128
+
129
+ <Tips />
130
+
131
+
132
+ [1]: https://nodejs.org/api/crypto.html#class-keyobject
133
+ [2]: https://nodejs.org/api/crypto.html#keyobjectexportoptions