@edirect/encrypt-modules 11.0.50 → 11.0.51

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.
package/dist/README.md CHANGED
@@ -1,34 +1,149 @@
1
1
  # @edirect/encrypt-modules
2
2
 
3
- Encryption utilities and modules for Edirect applications. Provides services and helpers for encrypting and decrypting data, including support for PGP and other algorithms.
3
+ Encryption utilities for eDirect NestJS applications. Provides four NestJS modules for different encryption algorithms: **PGP**, **Binary PGP**, **AES-256**, and **RSA** plus a **ZIP** module for password-protected archive creation.
4
4
 
5
5
  ## Features
6
6
 
7
- - PGP encryption and decryption helpers
8
- - Utilities for secure data handling
9
- - Integrates with NestJS and other Edirect modules
7
+ - **PGP** encryption/decryption using OpenPGP.js (`openpgp`)
8
+ - **Binary PGP** for binary data encryption
9
+ - **AES-256-CBC** (and other AES variants) using Node.js native `crypto`
10
+ - **RSA** encryption/decryption using `node-rsa`
11
+ - **ZIP** password-protected archive creation
12
+ - NestJS module integration for each encryption type
10
13
 
11
14
  ## Installation
12
15
 
13
- ```bash
16
+ ```sh
17
+ pnpm add @edirect/encrypt-modules
18
+ # or
14
19
  npm install @edirect/encrypt-modules
15
20
  ```
16
21
 
17
- ## Usage
22
+ ## Available Modules
18
23
 
19
- Import and use the encryption services in your application:
24
+ ### PGP Encryption (`PgpEncryptModule`)
20
25
 
21
- ```typescript
26
+ Asymmetric encryption using OpenPGP keys:
27
+
28
+ ```ts
29
+ import { Module } from '@nestjs/common';
30
+ import { PgpEncryptModule } from '@edirect/encrypt-modules';
31
+
32
+ @Module({
33
+ imports: [PgpEncryptModule],
34
+ })
35
+ export class AppModule {}
36
+ ```
37
+
38
+ ```ts
39
+ import { Injectable } from '@nestjs/common';
22
40
  import { PgpEncryptService } from '@edirect/encrypt-modules';
23
41
 
24
- const encrypted = await PgpEncryptService.encrypt(data, publicKey);
25
- const decrypted = await PgpEncryptService.decrypt(
42
+ @Injectable()
43
+ export class SecureDataService {
44
+ constructor(private readonly pgp: PgpEncryptService) {}
45
+
46
+ async encryptPayload(data: string, publicKey: string): Promise<string> {
47
+ return this.pgp.encrypt(publicKey, data);
48
+ }
49
+
50
+ async decryptPayload(
51
+ encryptedData: string,
52
+ privateKey: string,
53
+ passphrase?: string
54
+ ): Promise<string> {
55
+ return this.pgp.decrypt(privateKey, encryptedData, passphrase);
56
+ }
57
+ }
58
+ ```
59
+
60
+ **`PgpEncryptService` API:**
61
+
62
+ | Method | Signature | Description |
63
+ | --------- | ------------------------------------------------------------------------------- | ------------------------------------ |
64
+ | `encrypt` | `(pgpKey: string, dataToEncrypt: string): Promise<string>` | Encrypt data using a PGP public key |
65
+ | `decrypt` | `(pgpKey: string, encryptedData: string, passphrase?: string): Promise<string>` | Decrypt data using a PGP private key |
66
+
67
+ ### AES Encryption (`AesEncryptModule`)
68
+
69
+ Symmetric encryption using Node.js `crypto`:
70
+
71
+ ```ts
72
+ import { AesEncryptModule } from '@edirect/encrypt-modules';
73
+
74
+ @Module({ imports: [AesEncryptModule] })
75
+ export class AppModule {}
76
+ ```
77
+
78
+ ```ts
79
+ import { AesEncryptService } from '@edirect/encrypt-modules';
80
+
81
+ // Default: AES-256-CBC
82
+ const encrypted = aesService.encrypt(
83
+ 'secret data',
84
+ 'my-32-char-passphrase-here!!!!!'
85
+ );
86
+ const decrypted = aesService.decrypt(
26
87
  encrypted,
27
- privateKey,
28
- passphrase
88
+ 'my-32-char-passphrase-here!!!!!'
29
89
  );
90
+
91
+ // With custom IV and encoding
92
+ const encrypted2 = aesService.encrypt('data', passphrase, {
93
+ iv: customIv,
94
+ encryptionMethod: 'aes-256-cbc',
95
+ outputEncoding: 'base64',
96
+ });
30
97
  ```
31
98
 
32
- ## Environment Variables
99
+ **`AesEncryptService` API:**
100
+
101
+ | Method | Signature | Description |
102
+ | --------- | ----------------------------------------------------------------------------------------------------- | -------------------------- |
103
+ | `encrypt` | `(message: string, passphrase: CipherKey, options?: IaesEncryptOptionalParameters): string` | Synchronous AES encryption |
104
+ | `decrypt` | `(encryptedMessage: string, passphrase: BinaryLike, options?: IaesDecryptOptionalParameters): string` | Synchronous AES decryption |
105
+
106
+ ### RSA Encryption (`RsaEncryptModule`)
107
+
108
+ Asymmetric encryption using `node-rsa`:
109
+
110
+ ```ts
111
+ import { RsaEncryptModule } from '@edirect/encrypt-modules';
112
+
113
+ @Module({ imports: [RsaEncryptModule] })
114
+ export class AppModule {}
115
+ ```
116
+
117
+ ```ts
118
+ import { RsaEncryptService } from '@edirect/encrypt-modules';
119
+
120
+ const encrypted = rsaService.encrypt(data, 512, 'utf8');
121
+ const decrypted = rsaService.decrypt(encrypted, privateKey, 'utf8');
122
+ ```
123
+
124
+ ### ZIP with Password (`ZipEncryptModule`)
125
+
126
+ Create password-protected ZIP archives:
127
+
128
+ ```ts
129
+ import { ZipEncryptModule } from '@edirect/encrypt-modules';
130
+
131
+ @Module({ imports: [ZipEncryptModule] })
132
+ export class AppModule {}
133
+ ```
134
+
135
+ ## AES Optional Parameters
136
+
137
+ | Option | Type | Default | Description |
138
+ | ------------------ | ------------------ | --------------- | ---------------------------------- |
139
+ | `iv` | `BinaryLike` | Random | Initialization vector |
140
+ | `encryptionMethod` | `string` | `'aes-256-cbc'` | Cipher algorithm |
141
+ | `inputEncoding` | `Encoding` | `'utf8'` | Input data encoding |
142
+ | `outputEncoding` | `Encoding` | `'hex'` | Output encoding for encrypted data |
143
+ | `options` | `TransformOptions` | — | Additional stream options |
144
+
145
+ ## Security Notes
33
146
 
34
- This package does not require environment variables by default, but you may provide keys or secrets via environment variables as needed for your encryption setup.
147
+ - Never hardcode encryption keys in source code. Use environment variables.
148
+ - For PGP keys, store them in secure secret management (e.g., Kubernetes Secrets, AWS Secrets Manager).
149
+ - AES keys must be exactly 32 bytes for AES-256. Use a key derivation function (KDF) if your passphrase is shorter.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/encrypt-modules",
3
- "version": "11.0.46",
3
+ "version": "11.0.51",
4
4
  "description": "Encrypt Modules",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@nestjs/common": "^11.1.12",
20
+ "@nestjs/common": "^11.1.17",
21
21
  "archiver": "7.0.1",
22
22
  "archiver-zip-encrypted": "^2.0.0",
23
23
  "node-rsa": "1.1.1",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/archiver": "^7.0.0",
30
- "@types/node": "^25.0.10",
30
+ "@types/node": "^25.4.0",
31
31
  "@types/node-rsa": "^1.1.4",
32
32
  "@types/stream-buffers": "^3.0.8"
33
33
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/encrypt-modules",
3
- "version": "11.0.50",
3
+ "version": "11.0.51",
4
4
  "description": "Encrypt Modules",
5
5
  "packageScope": "@edirect",
6
6
  "main": "./dist/src/index.js",
@@ -18,7 +18,7 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "@nestjs/common": "^11.1.16",
21
+ "@nestjs/common": "^11.1.17",
22
22
  "archiver": "7.0.1",
23
23
  "archiver-zip-encrypted": "^2.0.0",
24
24
  "node-rsa": "1.1.1",
@@ -50,4 +50,4 @@
50
50
  }
51
51
  }
52
52
  }
53
- }
53
+ }