encryptbox 1.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JSLEEKR
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,434 @@
1
+ Metadata-Version: 2.4
2
+ Name: encryptbox
3
+ Version: 1.0.0
4
+ Summary: Encrypt files with envelope encryption, key rotation, and audit logging — no server required
5
+ Author-email: JSLEEKR <93jslee@gmail.com>
6
+ License: MIT
7
+ Keywords: encryption,envelope-encryption,key-rotation,cli,security
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Security :: Cryptography
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: click>=8.1
21
+ Requires-Dist: cryptography>=41.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0; extra == "dev"
24
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ <div align="center">
28
+
29
+ # encryptbox
30
+
31
+ ### Encrypt files with key rotation — no server required
32
+
33
+ [![Stars](https://img.shields.io/github/stars/JSLEEKR/encryptbox?style=for-the-badge)](https://github.com/JSLEEKR/encryptbox/stargazers)
34
+ [![License](https://img.shields.io/github/license/JSLEEKR/encryptbox?style=for-the-badge)](LICENSE)
35
+ [![Python](https://img.shields.io/badge/python-3.10+-blue?style=for-the-badge&logo=python&logoColor=white)](https://python.org)
36
+ [![Tests](https://img.shields.io/badge/tests-157_passed-brightgreen?style=for-the-badge)](tests/)
37
+
38
+ <br/>
39
+
40
+ **Envelope encryption + key rotation + audit log in a single CLI**
41
+
42
+ </div>
43
+
44
+ ---
45
+
46
+ ## Why This Exists
47
+
48
+ You need to encrypt config files, backups, or secrets. Your options are:
49
+
50
+ - **age** — simple, but no key rotation. Rotate the key = re-encrypt everything.
51
+ - **AWS KMS / HashiCorp Vault** — powerful, but you need infrastructure, IAM policies, network access.
52
+ - **GPG** — works, but the UX is from 1999 and key management is painful.
53
+
54
+ **encryptbox** gives you envelope encryption (the same pattern AWS KMS uses) in a local CLI. Rotate your master key without touching encrypted files. Every operation gets logged in a tamper-evident audit trail. No server, no cloud, no subscriptions.
55
+
56
+ ---
57
+
58
+ ## How It Works
59
+
60
+ ### Envelope Encryption
61
+
62
+ ```
63
+ ┌─────────────────────────────────────────────────┐
64
+ │ Your File │
65
+ │ │
66
+ │ plaintext ──► AES-256-GCM ──► ciphertext │
67
+ │ ▲ │
68
+ │ │ │
69
+ │ data key (random) │
70
+ │ │ │
71
+ │ X25519 wrap ──► wrapped data key │
72
+ │ ▲ │
73
+ │ │ │
74
+ │ master key (your keypair) │
75
+ └─────────────────────────────────────────────────┘
76
+ ```
77
+
78
+ 1. A **random data key** encrypts your file with AES-256-GCM
79
+ 2. The data key is **wrapped** (encrypted) with your X25519 public key
80
+ 3. Both the wrapped key and ciphertext go into a `.ebox` file
81
+
82
+ To **rotate**: unwrap the data key with the old master, re-wrap with the new master. The encrypted file data stays untouched.
83
+
84
+ ### Audit Chain
85
+
86
+ Every operation (encrypt, decrypt, rotate, keygen) is logged with an HMAC chain:
87
+
88
+ ```
89
+ entry[0].hmac ──► entry[1].prev_hmac ──► entry[1].hmac ──► entry[2].prev_hmac ──► ...
90
+ ```
91
+
92
+ Tamper with any entry and the chain breaks. Delete an entry and the chain breaks. The verification is `O(n)` and deterministic.
93
+
94
+ ---
95
+
96
+ ## Installation
97
+
98
+ ```bash
99
+ pip install encryptbox
100
+ ```
101
+
102
+ Or from source:
103
+
104
+ ```bash
105
+ git clone https://github.com/JSLEEKR/encryptbox.git
106
+ cd encryptbox
107
+ pip install -e ".[dev]"
108
+ ```
109
+
110
+ ### Requirements
111
+
112
+ - Python 3.10+
113
+ - [cryptography](https://cryptography.io/) (pyca/cryptography)
114
+ - [click](https://click.palletsprojects.com/) (CLI framework)
115
+
116
+ ---
117
+
118
+ ## Quick Start
119
+
120
+ ### 1. Initialize
121
+
122
+ ```bash
123
+ encryptbox init
124
+ # [OK] Keystore initialized
125
+ # Keystore created at: .encryptbox
126
+ # Run 'encryptbox keygen' to generate your first keypair.
127
+ ```
128
+
129
+ ### 2. Generate a keypair
130
+
131
+ ```bash
132
+ encryptbox keygen --label "my-laptop"
133
+ # [OK] Generated key: a1b2c3d4e5f6a7b8
134
+ # Label: my-laptop
135
+ # Key ID: a1b2c3d4e5f6a7b8
136
+ ```
137
+
138
+ ### 3. Encrypt a file
139
+
140
+ ```bash
141
+ encryptbox encrypt secrets.env
142
+ # [OK] Encrypted: secrets.env
143
+ # Output: secrets.env.ebox
144
+ ```
145
+
146
+ ### 4. Decrypt it back
147
+
148
+ ```bash
149
+ encryptbox decrypt secrets.env.ebox
150
+ # [OK] Decrypted: secrets.env.ebox
151
+ # Output: secrets.env
152
+ ```
153
+
154
+ ### 5. Rotate keys
155
+
156
+ ```bash
157
+ encryptbox rotate
158
+ # [OK] Key rotated
159
+ # Old key: a1b2c3d4e5f6a7b8 (deactivated)
160
+ # New key: f8e7d6c5b4a39281 (active)
161
+ # Files re-wrapped: 3
162
+ ```
163
+
164
+ ### 6. Check the audit log
165
+
166
+ ```bash
167
+ encryptbox audit
168
+ # [2026-03-28 14:00:01] INIT (by alice)
169
+ # [2026-03-28 14:00:02] KEYGEN key=a1b2c3d4e5f6a7b8 (by alice)
170
+ # [2026-03-28 14:00:05] ENCRYPT key=a1b2c3d4e5f6a7b8 secrets.env (by alice)
171
+ # [2026-03-28 14:01:00] ROTATE key=f8e7d6c5b4a39281 (by alice)
172
+ ```
173
+
174
+ ---
175
+
176
+ ## CLI Reference
177
+
178
+ ### Core Commands
179
+
180
+ | Command | Description |
181
+ |---------|-------------|
182
+ | `encryptbox init` | Initialize the keystore in the current directory |
183
+ | `encryptbox keygen` | Generate a new X25519 keypair |
184
+ | `encryptbox encrypt <file>` | Encrypt a file with envelope encryption |
185
+ | `encryptbox decrypt <file>` | Decrypt a `.ebox` file |
186
+ | `encryptbox rotate` | Rotate master key and re-wrap all `.ebox` files |
187
+ | `encryptbox audit` | Show the audit log |
188
+ | `encryptbox status` | Show keystore status and health |
189
+
190
+ ### Batch Commands
191
+
192
+ | Command | Description |
193
+ |---------|-------------|
194
+ | `encryptbox encrypt-dir <dir>` | Encrypt all files in a directory |
195
+ | `encryptbox decrypt-dir <dir>` | Decrypt all `.ebox` files in a directory |
196
+
197
+ ### Key Management
198
+
199
+ | Command | Description |
200
+ |---------|-------------|
201
+ | `encryptbox export-key` | Export a public key as hex |
202
+ | `encryptbox import-key <hex> --id <name>` | Import a public key |
203
+
204
+ ### Options
205
+
206
+ ```bash
207
+ # Encrypt with custom output path
208
+ encryptbox encrypt secret.txt -o /backup/secret.enc
209
+
210
+ # Encrypt for multiple recipients
211
+ encryptbox encrypt secret.txt -k key1 -k key2
212
+
213
+ # Remove original after encryption
214
+ encryptbox encrypt secret.txt --remove
215
+
216
+ # Encrypt only .env files in a directory
217
+ encryptbox encrypt-dir ./configs -p "*.env"
218
+
219
+ # Verify audit log integrity
220
+ encryptbox audit --verify
221
+
222
+ # Show last 5 audit entries
223
+ encryptbox audit --last 5
224
+
225
+ # Output audit as JSON
226
+ encryptbox audit --json-output
227
+
228
+ # Use a specific key for decryption
229
+ encryptbox decrypt secret.txt.ebox -k a1b2c3d4e5f6a7b8
230
+
231
+ # Specify project root
232
+ encryptbox --root /path/to/project encrypt file.txt
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Multi-Recipient Encryption
238
+
239
+ Encrypt a file so multiple people can decrypt it:
240
+
241
+ ```bash
242
+ # Alice generates a key and shares her public key
243
+ encryptbox keygen --label alice
244
+ encryptbox export-key
245
+ # Public key: 7a3f...
246
+
247
+ # Bob imports Alice's public key
248
+ encryptbox import-key 7a3f... --id alice-pub
249
+
250
+ # Bob encrypts for both himself and Alice
251
+ encryptbox encrypt shared-secret.txt -k bob-key-id -k alice-pub
252
+ ```
253
+
254
+ Both Alice and Bob can decrypt the file independently with their own private keys.
255
+
256
+ ---
257
+
258
+ ## Key Rotation
259
+
260
+ Key rotation re-wraps data keys without re-encrypting file data:
261
+
262
+ ```bash
263
+ encryptbox rotate
264
+ ```
265
+
266
+ What happens:
267
+ 1. A new X25519 keypair is generated
268
+ 2. All `.ebox` files in the project tree are found
269
+ 3. Each file's data key is unwrapped with the old key and re-wrapped with the new key
270
+ 4. The old key is marked as inactive
271
+ 5. The operation is logged in the audit trail
272
+
273
+ The encrypted data itself is **never touched** during rotation. This means:
274
+ - Rotation is fast (no I/O proportional to file sizes)
275
+ - File integrity is preserved
276
+ - You can verify by decrypting after rotation
277
+
278
+ ---
279
+
280
+ ## Audit Log
281
+
282
+ Every operation is logged with a tamper-evident HMAC chain:
283
+
284
+ ```bash
285
+ # View all entries
286
+ encryptbox audit
287
+
288
+ # Verify chain integrity
289
+ encryptbox audit --verify
290
+ # [OK] All 42 entries verified
291
+
292
+ # Export as JSON for analysis
293
+ encryptbox audit --json-output > audit.json
294
+ ```
295
+
296
+ ### What Gets Logged
297
+
298
+ | Field | Description |
299
+ |-------|-------------|
300
+ | `timestamp` | Unix timestamp |
301
+ | `action` | `init`, `keygen`, `encrypt`, `decrypt`, `rotate` |
302
+ | `key_id` | The key used |
303
+ | `file_path` | The file involved |
304
+ | `file_hash` | SHA-256 of the file |
305
+ | `user` | System username |
306
+ | `prev_hmac` | HMAC of the previous entry |
307
+ | `entry_hmac` | HMAC of this entry |
308
+
309
+ ### Tamper Detection
310
+
311
+ The audit log uses HMAC-SHA256 chaining. Each entry's HMAC includes the previous entry's HMAC, forming a hash chain. If any entry is modified, deleted, or inserted, `audit --verify` will detect it.
312
+
313
+ ---
314
+
315
+ ## File Format
316
+
317
+ Encrypted files use the `.ebox` binary format:
318
+
319
+ ```
320
+ EBOX (4 bytes) — magic bytes
321
+ VERSION (1 byte) — format version (currently 1)
322
+ NUM_RECIPIENTS (2 bytes) — number of recipient key entries
323
+
324
+ For each recipient:
325
+ KEY_ID_LEN (1 byte) — length of key ID
326
+ KEY_ID (variable) — key ID string
327
+ WRAPPED_LEN (4 bytes) — length of wrapped key data
328
+ WRAPPED_KEY (variable) — ephemeral public key + encrypted data key
329
+
330
+ ORIGINAL_HASH (32 bytes) — SHA-256 of original plaintext
331
+ ENCRYPTED_DATA (variable) — AES-256-GCM nonce + ciphertext
332
+ ```
333
+
334
+ ---
335
+
336
+ ## Architecture
337
+
338
+ ```
339
+ encryptbox/
340
+ ├── crypto.py # AES-256-GCM encryption, X25519 key wrapping
341
+ ├── keystore.py # On-disk key management, metadata
342
+ ├── envelope.py # Envelope encryption, .ebox format, key rotation
343
+ ├── audit.py # HMAC-chained append-only audit log
344
+ ├── operations.py # High-level orchestration (encrypt/decrypt/rotate)
345
+ └── cli.py # Click CLI interface
346
+ ```
347
+
348
+ ### Module Responsibilities
349
+
350
+ | Module | Responsibility |
351
+ |--------|---------------|
352
+ | `crypto` | Low-level crypto: AES-256-GCM encrypt/decrypt, X25519 key wrap/unwrap, HKDF key derivation |
353
+ | `keystore` | Key lifecycle: generate, store, load, list, deactivate, import/export keypairs |
354
+ | `envelope` | Envelope encryption: combine crypto + multi-recipient + serialization into `.ebox` format |
355
+ | `audit` | Append-only log with HMAC chain for tamper detection |
356
+ | `operations` | Orchestrate all modules: file I/O, batch ops, rotation, status |
357
+ | `cli` | User-facing CLI commands via Click |
358
+
359
+ ### Security Properties
360
+
361
+ - **AES-256-GCM** — authenticated encryption with 96-bit nonces (CSPRNG)
362
+ - **X25519** — Curve25519 key exchange for key wrapping
363
+ - **HKDF-SHA256** — key derivation from shared secrets
364
+ - **CSPRNG** — all random bytes from `os.urandom`
365
+ - **No custom crypto** — everything from pyca/cryptography
366
+
367
+ ---
368
+
369
+ ## Development
370
+
371
+ ```bash
372
+ git clone https://github.com/JSLEEKR/encryptbox.git
373
+ cd encryptbox
374
+ pip install -e ".[dev]"
375
+ pytest
376
+ ```
377
+
378
+ ### Running Tests
379
+
380
+ ```bash
381
+ # All tests
382
+ pytest
383
+
384
+ # With verbose output
385
+ pytest -v
386
+
387
+ # With coverage
388
+ pytest --cov=encryptbox --cov-report=term-missing
389
+
390
+ # Specific module
391
+ pytest tests/test_crypto.py
392
+ ```
393
+
394
+ ### Test Coverage
395
+
396
+ | Module | Tests | Coverage |
397
+ |--------|-------|----------|
398
+ | `crypto` | 27 | encrypt/decrypt, key wrapping, serialization, edge cases |
399
+ | `keystore` | 28 | init, keygen, retrieval, metadata, import/export |
400
+ | `envelope` | 17 | envelope encrypt/decrypt, multi-recipient, rotation, serialization |
401
+ | `audit` | 22 | logging, chain verification, tamper detection, persistence |
402
+ | `operations` | 33 | file encrypt/decrypt, rotation, batch ops, status, audit integration |
403
+ | `cli` | 20 | all CLI commands end-to-end |
404
+ | **Total** | **157** | |
405
+
406
+ ---
407
+
408
+ ## Comparison
409
+
410
+ | Feature | encryptbox | age | GPG | AWS KMS |
411
+ |---------|-----------|-----|-----|---------|
412
+ | Envelope encryption | Yes | No | No | Yes |
413
+ | Key rotation (no re-encrypt) | Yes | No | No | Yes |
414
+ | Audit log | Yes | No | No | CloudTrail |
415
+ | Multi-recipient | Yes | Yes | Yes | Via policies |
416
+ | No server required | Yes | Yes | Yes | No |
417
+ | Tamper-evident logging | Yes | No | No | No |
418
+ | Binary format | `.ebox` | `.age` | `.gpg` | N/A |
419
+ | CLI UX | Modern (Click) | Good | Legacy | AWS CLI |
420
+
421
+ ---
422
+
423
+ ## Security Considerations
424
+
425
+ - **Key storage**: Private keys are stored as raw bytes on disk. Use appropriate file permissions.
426
+ - **Memory**: Data keys exist in memory during encrypt/decrypt operations.
427
+ - **Not a replacement for KMS**: For production secrets management at scale, use a proper KMS. encryptbox is for developer workflows, local encryption, and backup protection.
428
+ - **Audit log secret**: The HMAC secret for the audit chain is stored in `.encryptbox/audit.secret`. Protect this file.
429
+
430
+ ---
431
+
432
+ ## License
433
+
434
+ [MIT](LICENSE) — JSLEEKR