Skip to main content

End-to-end encrypted QR code generator and scanner with forward secrecy

Project description

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.

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

cipherqr-1.0.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

cipherqr-1.0.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file cipherqr-1.0.0.tar.gz.

File metadata

  • Download URL: cipherqr-1.0.0.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for cipherqr-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3d1ae180b6cb347be09540b6ec06c56adf1c7de4f8635014d518a462aef6eb4d
MD5 92dc205994891f4738de2aca4deae7d9
BLAKE2b-256 6075e6895f4158ae2d8d1bb094eab5ab292f1ae3513868f10b1d39a7334fc02c

See more details on using hashes here.

File details

Details for the file cipherqr-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cipherqr-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for cipherqr-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d3bbc71b71ea151034fe1e4ffebe4462a52b15124d300bb6d2f2dc10458ed5c
MD5 7f0ea98a990eaee5327929bf830ef9d1
BLAKE2b-256 17f0cd96f85e64d4df3f4c80d4dbee459a425aaf075a3ef40ff4493ce75c1f3b

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