CipherQR
End-to-end encrypted QR codes with forward secrecy
CipherQR is a production-grade Python package for generating and scanning encrypted QR codes that only authorized recipients can decrypt. Each QR code uses ephemeral keys for forward secrecy and authenticated encryption to prevent tampering.
🔐 Key Features
- Forward Secrecy: Ephemeral X25519 keys per QR code
- Strong Encryption: ChaCha20-Poly1305 or AES-GCM AEAD cipher (auto-detected)
- Anti-Replay Protection: Time-based expiry (TTL)
- Wide Compatibility: Works with older cryptography library versions
- Optional QR Rendering: Styled QR codes with graceful fallback
- Secure Key Storage: Platform-appropriate key management
- Production Ready: Comprehensive testing and error handling
🚀 Quick Start
Installation
# Extract package
unzip CipherQR_FINAL.zip
cd CipherQR_FINAL
# Install core dependencies
pip install -r requirements.txt
# Install CipherQR
python setup.py install
# Optional: Install QR rendering support
pip install qrcode[pil] Pillow
Quick Test
# Verify installation
python examples/simple_test.py
Basic Usage
from CipherQR import CipherQRGenerator, CipherQRScanner
from CipherQR.keystore import KeyStore
# Setup
keystore = KeyStore()
private_key, public_key = keystore.get_or_generate_keypair()
# Generate encrypted QR
generator = CipherQRGenerator()
scanner = CipherQRScanner(private_key)
payload = {"message": "Hello, World!", "timestamp": "2025-09-02"}
qr_data = generator.generate(payload, public_key)
# Scan and decrypt
result = scanner.scan(qr_data)
print(f"Decrypted: {result.payload}")
🛡️ Security Model
Encryption Protocol
- Key Agreement: X25519 Elliptic Curve Diffie-Hellman
- Key Derivation: HKDF-SHA256 with context separation
- Encryption: ChaCha20-Poly1305 (preferred) or AES-GCM AEAD cipher
- Forward Secrecy: New ephemeral keys for each QR code
Compatibility
CipherQR automatically detects available AEAD ciphers:
- ChaCha20-Poly1305 (preferred, modern cryptography versions)
- AES-GCM (fallback, widely supported)
Wire Format
┌─────────┬──────────────────┬─────────┬─────────────┐
│ Version │ Ephemeral PubKey │ Nonce │ Ciphertext │
│ (1 byte)│ (32 bytes) │(12 bytes)│ (variable) │
└─────────┴──────────────────┴─────────┴─────────────┘
📖 Testing
# Quick compatibility test
python examples/simple_test.py
# Run full test suite
python -m pytest tests/ -v
# Individual test files
python tests/test_crypto.py
python tests/test_generator_scanner.py
python tests/test_keystore.py
🔧 Advanced Usage
Route-based Payloads
route_payload = {
"route": "/user/profile/123",
"action": "view"
}
qr_data = generator.generate(
payload=route_payload,
recipient_public_key=public_key,
payload_type="route"
)
Size Estimation
estimation = generator.estimate_qr_size(payload_size)
print(f"Base64 size: {estimation['base64_chars']} chars")
print(f"Single QR recommended: {estimation['recommended_single_qr']}")
QR Rendering (Optional)
try:
from CipherQR.qr_renderer import QRRenderer, QRStyle
renderer = QRRenderer()
style = QRStyle(module_color="#2563eb")
qr_image = renderer.render(qr_data, style=style)
renderer.save(qr_image, "encrypted_qr.png")
except ImportError:
print("QR rendering not available - install qrcode[pil] Pillow")
⚙️ Requirements
Core (Required)
- Python 3.8+
- cryptography >= 40.0.0
- cbor2 >= 5.4.0
Optional (QR Rendering)
- qrcode[pil] >= 7.4.0
- Pillow >= 9.0.0
🔍 Troubleshooting
Q: Getting "cannot import XChaCha20Poly1305" error?
A: This version uses ChaCha20-Poly1305 or AES-GCM with automatic fallback for compatibility.
Q: QR rendering not working?
A: QR rendering is optional: pip install qrcode[pil] Pillow
Q: Tests failing?
A: Run python examples/simple_test.py to isolate the issue.
📄 License
MIT License - see LICENSE for details.
✅ This version is compatible with older cryptography libraries and includes graceful fallbacks for all optional features.
Metadata
Release files for CipherQR 1.0.0
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 |
|---|---|---|---|---|
| cipherqr-1.0.0.tar.gz | 16.7 kB | Without provenance | Details for cipherqr-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cipherqr-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for cipherqr-1.0.0-py3-none-any.whl |
Total release size: 37.2 kB
Release files / cipherqr-1.0.0.tar.gz
| Download URL | cipherqr-1.0.0.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d1ae180b6cb347be09540b6ec06c56adf1c7de4f8635014d518a462aef6eb4d
|
|
BLAKE2b-256 checksum How to use checksums |
6075e6895f4158ae2d8d1bb094eab5ab292f1ae3513868f10b1d39a7334fc02c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / cipherqr-1.0.0-py3-none-any.whl
| Download URL | cipherqr-1.0.0-py3-none-any.whl |
|---|---|
| Size | 20.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d3bbc71b71ea151034fe1e4ffebe4462a52b15124d300bb6d2f2dc10458ed5c
|
|
BLAKE2b-256 checksum How to use checksums |
17f0cd96f85e64d4df3f4c80d4dbee459a425aaf075a3ef40ff4493ce75c1f3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for CipherQR 1.0.0
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.