FPE Plus
Format Preserving Encryption for Python
Encrypt dates, numbers, floats, and strings while preserving format and length.
Table of Contents
Features
- 🔒 Format Preserving Encryption (FPE) for dates, numbers, floats, and strings
- 🆕 Type-safe encryption/decryption:
- Encrypted integers are returned as
int - Encrypted floats are returned as
float - Encrypted dates are returned as
datetime - No conversion issues with databases (Oracle, PostgreSQL, SQL Server)
- Encrypted integers are returned as
- 🔤 Supports all characters (letters, digits, special characters)
- 📄 CSV encryption/decryption with column format specification
- 🛡️ No external dependencies (pure Python)
- 🏷️ Preserves length and format for structured data
Installation
pip install fpe_plus
Usage
Quick Start
from fpe_plus import FPETypeHandler, FPEExtended, FPECSVHandler
# Generate secure key and tweak
key = FPEExtended.generate_key()
tweak = FPEExtended.generate_tweak(7)
# Create a type handler
handler = FPETypeHandler(key, tweak, mode="FF3-1")
# Encrypt and decrypt a date (returns datetime)
date = "2023-12-25"
enc_date = handler.encrypt_date(date) # returns datetime
dec_date = handler.decrypt_date(enc_date) # returns datetime
print(f"Date: {date} -> {enc_date} -> {dec_date}")
# Encrypt and decrypt a float (returns float)
float_val = 123.456
enc_float = handler.encrypt_float(float_val) # returns float
dec_float = handler.decrypt_float(enc_float) # returns float
print(f"Float: {float_val} -> {enc_float} -> {dec_float}")
# Encrypt and decrypt a string (returns str)
text = "hello@world!123"
enc_str = handler.encrypt_string(text)
dec_str = handler.decrypt_string(enc_str)
print(f"String: {text} -> {enc_str} -> {dec_str}")
# Encrypt and decrypt digits (returns int)
number = 123456
enc_num = handler.encrypt_digit(number) # returns int
dec_num = handler.decrypt_digit(enc_num) # returns int
print(f"Digits: {number} -> {enc_num} -> {dec_num}")
# Encrypt and decrypt a CSV file
csv_handler = FPECSVHandler(key, tweak, mode="FF3-1")
formats = ['STRING', 'DATE', 'FLOAT', 'DIGITS']
csv_handler.encrypt_csv('input.csv', 'encrypted.csv', formats)
csv_handler.decrypt_csv('encrypted.csv', 'decrypted.csv', formats)
API Reference
FPEExtended
Core format-preserving encryption engine.
FPEExtended(key: bytes, tweak: bytes, mode: str = "FF3-1")key: 16, 24, or 32 bytestweak: 7 bytes for FF3-1mode: "FF3-1" (default)
generate_key(): Generate a secure random keygenerate_tweak(length=7): Generate a secure random tweakencrypt(plaintext: str, radix: int = None) -> str: Encrypt any stringdecrypt(ciphertext: str, radix: int = None) -> str: Decrypt any string
FPETypeHandler
Type-specific encryption/decryption.
FPETypeHandler(key: bytes, tweak: bytes, mode: str = "FF3-1")encrypt_date(date_input, date_format: str = "%Y-%m-%d", return_type=datetime) -> datetime|strdecrypt_date(ciphertext, date_format: str = "%Y-%m-%d", return_type=datetime) -> datetime|strencrypt_float(value, return_type=float) -> float|strdecrypt_float(ciphertext, return_type=float) -> float|strencrypt_digit(value, return_type=int) -> int|strdecrypt_digit(ciphertext, return_type=int) -> int|strencrypt_string(plaintext: str) -> strdecrypt_string(ciphertext: str) -> str
FPECSVHandler
CSV column-wise encryption/decryption.
FPECSVHandler(key: bytes, tweak: bytes, mode: str = "FF3-1")encrypt_csv(input_path: str, output_path: str, formats: list)decrypt_csv(input_path: str, output_path: str, formats: list)formats: List of column types ('DATE','FLOAT','STRING','DIGITS')
Developer Tips & Best Practices
- Always use secure random keys and tweaks for production.
- Specify correct column formats for CSV encryption.
- For digits, ensure even length for FF3-1 compatibility (handler pads automatically).
- Use caching for repeated values to improve performance.
- All encryption is reversible if you keep the key and tweak safe.
- No external dependencies: works out-of-the-box with Python 3.7+.
Dependencies
None (uses Python standard library).
License
This project is licensed under the MIT License.
Author & Contact
Vasudev Jaiswal
Email: vasudevjaiswal786@gmail.com
Made with ❤️ by Vasudev Jaiswal
Metadata
Release files for fpe-plus 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fpe_plus-1.1.1.tar.gz | 11.9 kB | Without provenance | Details for fpe_plus-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fpe_plus-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for fpe_plus-1.1.1-py3-none-any.whl |
Total release size: 22.5 kB
Release files / fpe_plus-1.1.1.tar.gz
| Download URL | fpe_plus-1.1.1.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccdc3c3de33283175da8343af7aa66c31951d9ca16d2b9056c8ca3d8eba04b94
|
|
BLAKE2b-256 checksum How to use checksums |
883547df61121416b8298e8bd38d98f92148c8f618a2054f15a12a2c9aa0d859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Release files / fpe_plus-1.1.1-py3-none-any.whl
| Download URL | fpe_plus-1.1.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d79f7a6d9cbc50d325a35bbd9be64bc216bf7edcf136fce67b6e5d2f132b62a5
|
|
BLAKE2b-256 checksum How to use checksums |
aa6e269e65957eb5725707a46fb13ecb37bc40bedf36a5080caf582c067c4d81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Security for fpe-plus 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.