securepayload 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.
- securepayload-1.0.0/PKG-INFO +309 -0
- securepayload-1.0.0/README.md +282 -0
- securepayload-1.0.0/pyproject.toml +56 -0
- securepayload-1.0.0/securepayload/__init__.py +124 -0
- securepayload-1.0.0/securepayload/aes.py +170 -0
- securepayload-1.0.0/securepayload/encryption_service.py +59 -0
- securepayload-1.0.0/securepayload/env.py +56 -0
- securepayload-1.0.0/securepayload/exceptions.py +14 -0
- securepayload-1.0.0/securepayload/vectors.py +9 -0
- securepayload-1.0.0/securepayload.egg-info/PKG-INFO +309 -0
- securepayload-1.0.0/securepayload.egg-info/SOURCES.txt +14 -0
- securepayload-1.0.0/securepayload.egg-info/dependency_links.txt +1 -0
- securepayload-1.0.0/securepayload.egg-info/requires.txt +5 -0
- securepayload-1.0.0/securepayload.egg-info/top_level.txt +1 -0
- securepayload-1.0.0/setup.cfg +4 -0
- securepayload-1.0.0/tests/test_encryption.py +73 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: securepayload
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: SecurePayload — Python AES encryption library for API payloads. Encrypt and decrypt with securepayload.encrypt() and securepayload.decrypt().
|
|
5
|
+
Author-email: zfhassaan <zfhassaan@gmail.com>
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Project-URL: Homepage, https://github.com/zfhassaan/securepayload
|
|
8
|
+
Project-URL: Documentation, https://github.com/zfhassaan/securepayload#readme
|
|
9
|
+
Project-URL: Source, https://github.com/zfhassaan/securepayload
|
|
10
|
+
Project-URL: Issues, https://github.com/zfhassaan/securepayload/issues
|
|
11
|
+
Keywords: aes,aes-encryption,api-payload,cryptography,encryption,payload-encryption,python-security,secure-payload,webhook-encryption
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Security :: Cryptography
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: pycryptodome>=3.20.0
|
|
24
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<img src="assets/banner.png" alt="SecurePayload — Python AES API Payload Encryption Library" width="100%" />
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<img src="assets/logo.png" alt="SecurePayload logo" width="50" />
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
<h1 align="center">SecurePayload</h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<strong>Python AES encryption library for secure API payload handling</strong>
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
Encrypt and decrypt JSON API payloads, webhook bodies, and request data with a simple two-call API —
|
|
44
|
+
<code>securepayload.encrypt()</code> and <code>securepayload.decrypt()</code>
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
<p align="center">
|
|
48
|
+
<a href="#installation">Installation</a> •
|
|
49
|
+
<a href="#quick-start">Quick Start</a> •
|
|
50
|
+
<a href="#usage">Usage</a> •
|
|
51
|
+
<a href="#api-reference">API Reference</a> •
|
|
52
|
+
<a href="#testing">Testing</a>
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<img src="https://img.shields.io/badge/python-3.9+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python 3.9+" />
|
|
57
|
+
<img src="https://img.shields.io/badge/AES--128--ECB-14b8a6?style=flat-square" alt="AES-128-ECB" />
|
|
58
|
+
<img src="https://img.shields.io/badge/license-Proprietary-64748b?style=flat-square" alt="License" />
|
|
59
|
+
</p>
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Overview
|
|
64
|
+
|
|
65
|
+
**SecurePayload** is a lightweight Python cryptography library built for developers who need to **encrypt API request bodies** and **decrypt encrypted webhook or HTTP payloads**. It uses AES-128-ECB with PKCS#7 padding and Base64 output — compatible with existing encrypted API integrations.
|
|
66
|
+
|
|
67
|
+
Ideal for:
|
|
68
|
+
|
|
69
|
+
- Python microservices sending encrypted API requests
|
|
70
|
+
- Webhook receivers decrypting incoming payloads
|
|
71
|
+
- Background workers and ETL pipelines handling secure JSON data
|
|
72
|
+
- Integration scripts bridging encrypted API endpoints
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import securepayload
|
|
76
|
+
|
|
77
|
+
securepayload.bootstrap()
|
|
78
|
+
|
|
79
|
+
encrypted = securepayload.encrypt({"order_no": "m123", "channel": "CARD"})
|
|
80
|
+
decrypted = securepayload.decrypt(encrypted)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
| Feature | Description |
|
|
88
|
+
|---------|-------------|
|
|
89
|
+
| **Simple API** | `securepayload.encrypt()` and `securepayload.decrypt()` — minimal boilerplate |
|
|
90
|
+
| **API payload ready** | JSON dicts and lists encrypted automatically |
|
|
91
|
+
| **Environment-based keys** | Configure via `securepayload.bootstrap()` or `configure(key=...)` |
|
|
92
|
+
| **Selective field encryption** | `Aes.obj_pipe()` for encrypting individual record fields |
|
|
93
|
+
| **Typed exceptions** | `InvalidKeyError`, `EncryptionError`, `DecryptionError` |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Requirements
|
|
98
|
+
|
|
99
|
+
- Python **3.9+**
|
|
100
|
+
- [PyCryptodome](https://pycryptodome.readthedocs.io/)
|
|
101
|
+
- [python-dotenv](https://github.com/theskumar/python-dotenv)
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Installation
|
|
106
|
+
|
|
107
|
+
### From PyPI
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pip install securepayload
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### From source (development)
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
git clone https://github.com/zfhassaan/securepayload.git
|
|
117
|
+
cd securepayload
|
|
118
|
+
python -m venv env
|
|
119
|
+
|
|
120
|
+
# Windows
|
|
121
|
+
env\Scripts\activate
|
|
122
|
+
|
|
123
|
+
# macOS / Linux
|
|
124
|
+
source env/bin/activate
|
|
125
|
+
|
|
126
|
+
pip install -e ".[dev]"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Configure your AES key
|
|
130
|
+
|
|
131
|
+
Create a `.env` file (or set the variable in your environment):
|
|
132
|
+
|
|
133
|
+
```env
|
|
134
|
+
SECURITY_AES_KEY=your-16-char-key
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
> **Security:** Never commit production keys. Keep `.env` out of version control.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Quick start
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
import securepayload
|
|
145
|
+
|
|
146
|
+
securepayload.bootstrap() # loads .env and configures the key
|
|
147
|
+
|
|
148
|
+
payload = {"order_no": "26168785012837", "channel": "CARD"}
|
|
149
|
+
|
|
150
|
+
encrypted = securepayload.encrypt(payload)
|
|
151
|
+
decrypted = securepayload.decrypt(encrypted)
|
|
152
|
+
|
|
153
|
+
print(encrypted) # Base64 ciphertext
|
|
154
|
+
print(decrypted) # Original dict
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
python examples/basic_usage.py
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Usage
|
|
164
|
+
|
|
165
|
+
### Encrypt and decrypt API payloads
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
import securepayload
|
|
169
|
+
|
|
170
|
+
# Load key from .env (searches upward from cwd)
|
|
171
|
+
securepayload.bootstrap()
|
|
172
|
+
|
|
173
|
+
# Or pass key explicitly
|
|
174
|
+
securepayload.configure(key="your-16-char-key")
|
|
175
|
+
|
|
176
|
+
# Encrypt JSON payload → Base64 string
|
|
177
|
+
ciphertext = securepayload.encrypt({"order_no": "m123", "channel": "CARD"})
|
|
178
|
+
|
|
179
|
+
# Decrypt → dict (auto JSON-parsed)
|
|
180
|
+
data = securepayload.decrypt(ciphertext)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
| Input to `decrypt()` | Result |
|
|
184
|
+
|----------------------|--------|
|
|
185
|
+
| Base64 `str` | Decrypted; JSON-parsed when valid JSON |
|
|
186
|
+
| `dict` / `list` | Returned unchanged |
|
|
187
|
+
| Other | `None` |
|
|
188
|
+
|
|
189
|
+
### HTTP integration
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
import os
|
|
193
|
+
import requests
|
|
194
|
+
import securepayload
|
|
195
|
+
|
|
196
|
+
securepayload.configure(key=os.environ["SECURITY_AES_KEY"])
|
|
197
|
+
|
|
198
|
+
body = securepayload.encrypt({"event": "order.updated", "order_no": "m123"})
|
|
199
|
+
requests.post("https://api.example.com/webhook", data=body)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Error handling
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
import securepayload
|
|
206
|
+
from securepayload.exceptions import DecryptionError, InvalidKeyError
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
securepayload.configure(key="")
|
|
210
|
+
except InvalidKeyError:
|
|
211
|
+
...
|
|
212
|
+
|
|
213
|
+
try:
|
|
214
|
+
securepayload.decrypt("invalid-ciphertext")
|
|
215
|
+
except DecryptionError:
|
|
216
|
+
...
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Advanced: selective field encryption
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from securepayload import Aes
|
|
223
|
+
|
|
224
|
+
aes = Aes(key="your-16-char-key")
|
|
225
|
+
record = {"name": "public", "token": "secret-value"}
|
|
226
|
+
sealed = aes.obj_pipe(record, mode=1, props=["token"])
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Examples
|
|
232
|
+
|
|
233
|
+
| Script | Description |
|
|
234
|
+
|--------|-------------|
|
|
235
|
+
| `examples/basic_usage.py` | Encrypt/decrypt demo |
|
|
236
|
+
| `examples/vector_test.py` | Known ciphertext vector validation |
|
|
237
|
+
| `examples/run_tests.py` | Runs the pytest suite |
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
python examples/basic_usage.py
|
|
241
|
+
python examples/vector_test.py
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Testing
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
pip install -e ".[dev]"
|
|
250
|
+
pytest -v
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Cryptographic specification
|
|
256
|
+
|
|
257
|
+
| Setting | Value |
|
|
258
|
+
|---------|-------|
|
|
259
|
+
| Algorithm | AES-128-ECB |
|
|
260
|
+
| Padding | PKCS#7 |
|
|
261
|
+
| Output | Base64 |
|
|
262
|
+
| Key | 16-byte UTF-8 string (padded/truncated) |
|
|
263
|
+
|
|
264
|
+
### Known test vectors
|
|
265
|
+
|
|
266
|
+
| Plaintext | Ciphertext |
|
|
267
|
+
|-----------|------------|
|
|
268
|
+
| `{"test":"hello"}` | `4f58KzglCzu10lH/7VxEy+tBHZ/TaMAkHQSH/SnDBEI=` |
|
|
269
|
+
| `{"order_no":"m123"}` | `3zBcPh7pTI8VHlNt6MdfQxHTv+BOkN5Gg5gmBxzQ07g=` |
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Project structure
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
├── assets/
|
|
277
|
+
│ ├── banner.png # README banner
|
|
278
|
+
│ └── logo.png # Project logo
|
|
279
|
+
├── securepayload/ # Main package
|
|
280
|
+
│ ├── __init__.py # securepayload.encrypt / decrypt
|
|
281
|
+
│ ├── aes.py
|
|
282
|
+
│ ├── encryption_service.py
|
|
283
|
+
│ └── exceptions.py
|
|
284
|
+
├── examples/
|
|
285
|
+
├── tests/
|
|
286
|
+
└── docs/
|
|
287
|
+
└── API.md
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Security considerations
|
|
293
|
+
|
|
294
|
+
- **ECB mode** is retained for compatibility with existing encrypted API systems.
|
|
295
|
+
- Use `.env` locally and a secrets manager in production.
|
|
296
|
+
- Rotate keys through your deployment pipeline.
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Documentation
|
|
301
|
+
|
|
302
|
+
- [API reference](docs/API.md)
|
|
303
|
+
- Repository: [github.com/zfhassaan/securepayload](https://github.com/zfhassaan/securepayload)
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
Proprietary — internal tooling. Use according to your organization's policies.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/banner.png" alt="SecurePayload — Python AES API Payload Encryption Library" width="100%" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="assets/logo.png" alt="SecurePayload logo" width="50" />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<h1 align="center">SecurePayload</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<strong>Python AES encryption library for secure API payload handling</strong>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
Encrypt and decrypt JSON API payloads, webhook bodies, and request data with a simple two-call API —
|
|
17
|
+
<code>securepayload.encrypt()</code> and <code>securepayload.decrypt()</code>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="#installation">Installation</a> •
|
|
22
|
+
<a href="#quick-start">Quick Start</a> •
|
|
23
|
+
<a href="#usage">Usage</a> •
|
|
24
|
+
<a href="#api-reference">API Reference</a> •
|
|
25
|
+
<a href="#testing">Testing</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<img src="https://img.shields.io/badge/python-3.9+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python 3.9+" />
|
|
30
|
+
<img src="https://img.shields.io/badge/AES--128--ECB-14b8a6?style=flat-square" alt="AES-128-ECB" />
|
|
31
|
+
<img src="https://img.shields.io/badge/license-Proprietary-64748b?style=flat-square" alt="License" />
|
|
32
|
+
</p>
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Overview
|
|
37
|
+
|
|
38
|
+
**SecurePayload** is a lightweight Python cryptography library built for developers who need to **encrypt API request bodies** and **decrypt encrypted webhook or HTTP payloads**. It uses AES-128-ECB with PKCS#7 padding and Base64 output — compatible with existing encrypted API integrations.
|
|
39
|
+
|
|
40
|
+
Ideal for:
|
|
41
|
+
|
|
42
|
+
- Python microservices sending encrypted API requests
|
|
43
|
+
- Webhook receivers decrypting incoming payloads
|
|
44
|
+
- Background workers and ETL pipelines handling secure JSON data
|
|
45
|
+
- Integration scripts bridging encrypted API endpoints
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import securepayload
|
|
49
|
+
|
|
50
|
+
securepayload.bootstrap()
|
|
51
|
+
|
|
52
|
+
encrypted = securepayload.encrypt({"order_no": "m123", "channel": "CARD"})
|
|
53
|
+
decrypted = securepayload.decrypt(encrypted)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
| Feature | Description |
|
|
61
|
+
|---------|-------------|
|
|
62
|
+
| **Simple API** | `securepayload.encrypt()` and `securepayload.decrypt()` — minimal boilerplate |
|
|
63
|
+
| **API payload ready** | JSON dicts and lists encrypted automatically |
|
|
64
|
+
| **Environment-based keys** | Configure via `securepayload.bootstrap()` or `configure(key=...)` |
|
|
65
|
+
| **Selective field encryption** | `Aes.obj_pipe()` for encrypting individual record fields |
|
|
66
|
+
| **Typed exceptions** | `InvalidKeyError`, `EncryptionError`, `DecryptionError` |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Requirements
|
|
71
|
+
|
|
72
|
+
- Python **3.9+**
|
|
73
|
+
- [PyCryptodome](https://pycryptodome.readthedocs.io/)
|
|
74
|
+
- [python-dotenv](https://github.com/theskumar/python-dotenv)
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Installation
|
|
79
|
+
|
|
80
|
+
### From PyPI
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install securepayload
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### From source (development)
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
git clone https://github.com/zfhassaan/securepayload.git
|
|
90
|
+
cd securepayload
|
|
91
|
+
python -m venv env
|
|
92
|
+
|
|
93
|
+
# Windows
|
|
94
|
+
env\Scripts\activate
|
|
95
|
+
|
|
96
|
+
# macOS / Linux
|
|
97
|
+
source env/bin/activate
|
|
98
|
+
|
|
99
|
+
pip install -e ".[dev]"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Configure your AES key
|
|
103
|
+
|
|
104
|
+
Create a `.env` file (or set the variable in your environment):
|
|
105
|
+
|
|
106
|
+
```env
|
|
107
|
+
SECURITY_AES_KEY=your-16-char-key
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
> **Security:** Never commit production keys. Keep `.env` out of version control.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Quick start
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import securepayload
|
|
118
|
+
|
|
119
|
+
securepayload.bootstrap() # loads .env and configures the key
|
|
120
|
+
|
|
121
|
+
payload = {"order_no": "26168785012837", "channel": "CARD"}
|
|
122
|
+
|
|
123
|
+
encrypted = securepayload.encrypt(payload)
|
|
124
|
+
decrypted = securepayload.decrypt(encrypted)
|
|
125
|
+
|
|
126
|
+
print(encrypted) # Base64 ciphertext
|
|
127
|
+
print(decrypted) # Original dict
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
python examples/basic_usage.py
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Usage
|
|
137
|
+
|
|
138
|
+
### Encrypt and decrypt API payloads
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import securepayload
|
|
142
|
+
|
|
143
|
+
# Load key from .env (searches upward from cwd)
|
|
144
|
+
securepayload.bootstrap()
|
|
145
|
+
|
|
146
|
+
# Or pass key explicitly
|
|
147
|
+
securepayload.configure(key="your-16-char-key")
|
|
148
|
+
|
|
149
|
+
# Encrypt JSON payload → Base64 string
|
|
150
|
+
ciphertext = securepayload.encrypt({"order_no": "m123", "channel": "CARD"})
|
|
151
|
+
|
|
152
|
+
# Decrypt → dict (auto JSON-parsed)
|
|
153
|
+
data = securepayload.decrypt(ciphertext)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
| Input to `decrypt()` | Result |
|
|
157
|
+
|----------------------|--------|
|
|
158
|
+
| Base64 `str` | Decrypted; JSON-parsed when valid JSON |
|
|
159
|
+
| `dict` / `list` | Returned unchanged |
|
|
160
|
+
| Other | `None` |
|
|
161
|
+
|
|
162
|
+
### HTTP integration
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
import os
|
|
166
|
+
import requests
|
|
167
|
+
import securepayload
|
|
168
|
+
|
|
169
|
+
securepayload.configure(key=os.environ["SECURITY_AES_KEY"])
|
|
170
|
+
|
|
171
|
+
body = securepayload.encrypt({"event": "order.updated", "order_no": "m123"})
|
|
172
|
+
requests.post("https://api.example.com/webhook", data=body)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Error handling
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
import securepayload
|
|
179
|
+
from securepayload.exceptions import DecryptionError, InvalidKeyError
|
|
180
|
+
|
|
181
|
+
try:
|
|
182
|
+
securepayload.configure(key="")
|
|
183
|
+
except InvalidKeyError:
|
|
184
|
+
...
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
securepayload.decrypt("invalid-ciphertext")
|
|
188
|
+
except DecryptionError:
|
|
189
|
+
...
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Advanced: selective field encryption
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from securepayload import Aes
|
|
196
|
+
|
|
197
|
+
aes = Aes(key="your-16-char-key")
|
|
198
|
+
record = {"name": "public", "token": "secret-value"}
|
|
199
|
+
sealed = aes.obj_pipe(record, mode=1, props=["token"])
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Examples
|
|
205
|
+
|
|
206
|
+
| Script | Description |
|
|
207
|
+
|--------|-------------|
|
|
208
|
+
| `examples/basic_usage.py` | Encrypt/decrypt demo |
|
|
209
|
+
| `examples/vector_test.py` | Known ciphertext vector validation |
|
|
210
|
+
| `examples/run_tests.py` | Runs the pytest suite |
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
python examples/basic_usage.py
|
|
214
|
+
python examples/vector_test.py
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Testing
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pip install -e ".[dev]"
|
|
223
|
+
pytest -v
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Cryptographic specification
|
|
229
|
+
|
|
230
|
+
| Setting | Value |
|
|
231
|
+
|---------|-------|
|
|
232
|
+
| Algorithm | AES-128-ECB |
|
|
233
|
+
| Padding | PKCS#7 |
|
|
234
|
+
| Output | Base64 |
|
|
235
|
+
| Key | 16-byte UTF-8 string (padded/truncated) |
|
|
236
|
+
|
|
237
|
+
### Known test vectors
|
|
238
|
+
|
|
239
|
+
| Plaintext | Ciphertext |
|
|
240
|
+
|-----------|------------|
|
|
241
|
+
| `{"test":"hello"}` | `4f58KzglCzu10lH/7VxEy+tBHZ/TaMAkHQSH/SnDBEI=` |
|
|
242
|
+
| `{"order_no":"m123"}` | `3zBcPh7pTI8VHlNt6MdfQxHTv+BOkN5Gg5gmBxzQ07g=` |
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Project structure
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
├── assets/
|
|
250
|
+
│ ├── banner.png # README banner
|
|
251
|
+
│ └── logo.png # Project logo
|
|
252
|
+
├── securepayload/ # Main package
|
|
253
|
+
│ ├── __init__.py # securepayload.encrypt / decrypt
|
|
254
|
+
│ ├── aes.py
|
|
255
|
+
│ ├── encryption_service.py
|
|
256
|
+
│ └── exceptions.py
|
|
257
|
+
├── examples/
|
|
258
|
+
├── tests/
|
|
259
|
+
└── docs/
|
|
260
|
+
└── API.md
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Security considerations
|
|
266
|
+
|
|
267
|
+
- **ECB mode** is retained for compatibility with existing encrypted API systems.
|
|
268
|
+
- Use `.env` locally and a secrets manager in production.
|
|
269
|
+
- Rotate keys through your deployment pipeline.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Documentation
|
|
274
|
+
|
|
275
|
+
- [API reference](docs/API.md)
|
|
276
|
+
- Repository: [github.com/zfhassaan/securepayload](https://github.com/zfhassaan/securepayload)
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## License
|
|
281
|
+
|
|
282
|
+
Proprietary — internal tooling. Use according to your organization's policies.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "securepayload"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "SecurePayload — Python AES encryption library for API payloads. Encrypt and decrypt with securepayload.encrypt() and securepayload.decrypt()."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "Proprietary" }
|
|
12
|
+
authors = [{ name = "zfhassaan", email = "zfhassaan@gmail.com" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"aes",
|
|
15
|
+
"aes-encryption",
|
|
16
|
+
"api-payload",
|
|
17
|
+
"cryptography",
|
|
18
|
+
"encryption",
|
|
19
|
+
"payload-encryption",
|
|
20
|
+
"python-security",
|
|
21
|
+
"secure-payload",
|
|
22
|
+
"webhook-encryption",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"Topic :: Security :: Cryptography",
|
|
33
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
34
|
+
]
|
|
35
|
+
dependencies = [
|
|
36
|
+
"pycryptodome>=3.20.0",
|
|
37
|
+
"python-dotenv>=1.0.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = [
|
|
42
|
+
"pytest>=8.0.0",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://github.com/zfhassaan/securepayload"
|
|
47
|
+
Documentation = "https://github.com/zfhassaan/securepayload#readme"
|
|
48
|
+
Source = "https://github.com/zfhassaan/securepayload"
|
|
49
|
+
Issues = "https://github.com/zfhassaan/securepayload/issues"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["."]
|
|
53
|
+
include = ["securepayload*"]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|