Skip to main content

Lightweight, production-grade AES/Fernet encryption & deterministic hashing library.

Project description

🟦 Mores-Encryption

Python Encryption PyPI

A Lightweight, Production-Ready Encryption Library for Python

Mores-Encryption is a clean, minimal, plug-and-play encryption library designed to make securing sensitive data effortless. Built on top of industry-standard AES-128 (Fernet), it provides simple helpers for:

✔ Encrypting & decrypting strings
✔ Deterministic hashing (searchable encryption)
✔ Secure JSON encryption
✔ Automatic key handling
✔ URL-safe output

Perfect for securing PII, emails, IDs, session tokens, API keys, medical data, or database fields across any Python backend.

Mores-Encryption removes the repetitive boilerplate and cryptographic complexity so you can focus on building — not configuring.


🔒 Features

🔐 Simple AES-128 Encryption

One-line methods: encrypt() and decrypt()

🔎 Deterministic Hashing for Search

Search encrypted fields using hash()
(same input + same salt = same output)

📦 JSON Encryption Support

Encrypt entire dictionaries with encrypt_json() and decrypt_json()

⚙️ Automatic Key Management

Loads ENCRYPTION_KEY from environment or generates a secure key if missing

🪶 Lightweight & Zero-Config

Only one dependency: cryptography

🌐 Works Everywhere

FastAPI, Django, Flask, LangChain, Redis, MongoDB, SQL, background jobs — plug it into anything.


📦 Installation

pip install mores-encryption

⚙️ Setup

Generate a secure encryption key:

python -c "from cryptography.fernet import Fernet; print('ENCRYPTION_KEY=' + Fernet.generate_key().decode())"

Save it in .env:

ENCRYPTION_KEY=your_generated_key_here

🚀 Usage

1. Encrypt & Decrypt

from mores_encryption.encryption import encryption_service

secret = "My Secret Data"

encrypted = encryption_service.encrypt(secret)
print("Encrypted:", encrypted)

decrypted = encryption_service.decrypt(encrypted)
print("Decrypted:", decrypted)

2. Deterministic Hashing

Perfect for searching encrypted emails, IDs, etc.

email = "user@example.com"
salt = "my_static_salt"

hashed = encryption_service.hash(email, salt)
print(hashed)

3. JSON Encryption

data = {"card": "1234-5678-9012-3456"}

encrypted = encryption_service.encrypt_json(data)
print(encrypted)

decrypted = encryption_service.decrypt_json(encrypted)
print(decrypted)

🧪 Why Use Mores-Encryption?

Because encryption shouldn't be painful.

Most developers struggle with cryptographic setup — salts, key formats, byte handling, serialization, JSON encoding, PBKDF2 — and end up copying the same boilerplate between projects.

Mores-Encryption gives you:

  • Clean API
  • Strong security defaults
  • Minimal code surface
  • Reusable across all your projects
  • Faster development + fewer mistakes

Configuration

The library uses environment variables for configuration. You can set these in your .env file or export them in your shell.

Variable Description Required Default
ENCRYPTION_KEY Base64-encoded 32-byte Fernet key. No (Auto-generated if missing) N/A

Key & Salt Generation

Run these commands in your terminal to generate secure values for your .env file:

Generate Encryption Key:

python -c "from cryptography.fernet import Fernet; print('ENCRYPTION_KEY=' + Fernet.generate_key().decode())"

Generate Salt (for deterministic hashing):

python -c "import secrets; print('EMAIL_SALT=' + secrets.token_urlsafe(16))"

Step-by-Step Setup:

  1. Run the commands above.
  2. Copy the output (e.g., ENCRYPTION_KEY=...).
  3. Paste it into your .env file in the project root.

Note: For a complete integration example, refer to integration.ipynb (if included in the examples).


Security Implementation Details

  • Encryption: cryptography.fernet.Fernet (AES-128 CBC with PKCS7 padding, HMAC-SHA256 for integrity).
  • Hashing: PBKDF2HMAC-SHA256 with configurable iterations (default: 200,000) and a 32-byte output length.
  • Encoding: All outputs are URL-safe Base64 encoded strings.

📚 Documentation & Source Code

GitHub: https://github.com/HATAKEkakshi/mores-encryption


License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mores_encryption-0.1.5.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mores_encryption-0.1.5-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mores_encryption-0.1.5.tar.gz.

File metadata

  • Download URL: mores_encryption-0.1.5.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mores_encryption-0.1.5.tar.gz
Algorithm Hash digest
SHA256 18addc7bf6d414f17777d98b638bd774b6c0cedfaca95ecb09407f09233add1e
MD5 d4cff37ada7b4809c80b18e98086add5
BLAKE2b-256 0c480886739c47e0d3f584005d307d54287f59c6aed059cc36ff10b0a4cc0ca5

See more details on using hashes here.

File details

Details for the file mores_encryption-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for mores_encryption-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e88a47a11d71da1f9a9ff845197ec20f887f30824b94662147daac99b3a199e2
MD5 3318f2f00bf36b4249af21878c3adc92
BLAKE2b-256 e78c39b66ae0ac3e54fa7ce0b3b711417db52ccb69249d90b4cefdcf7d37c79a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page