Pixel-level AES video encryption with real-time GPU-accelerated decryption
Project description
๐ Fort Spy
Pixel-Level Video Encryption & Real-Time Decryption Technology
Fort Spy is a military-grade video encryption system that operates at the pixel level, encrypting raw RGB data of every video frame using AES-256. It includes a dedicated Fort Spy Player that decrypts frames in real-time during playback, ensuring seamless and secure viewing with GPU acceleration.
โจ Features
๐ Pixel-Level Encryption
- Encrypts raw RGB pixel data of each video frame individually
- Supports AES-128, AES-192, and AES-256 encryption
- Three cipher modes: CBC, CTR (default), and GCM (authenticated)
- Per-frame nonce derivation prevents pattern analysis across frames
- HMAC-based header integrity verification
๐ฌ Fort Spy Player
- Dedicated video player with real-time decryption during playback
- Multi-threaded frame buffering for smooth, low-latency viewing
- Play/Pause, Seek, Fullscreen, Speed Control (0.25x โ 4x)
- Real-time performance overlay (FPS, decode time, throughput)
- Secure key input dialog (GUI or terminal)
- Progress bar and frame counter
โก GPU Acceleration
- OpenCL support via PyOpenCL
- CUDA support via CuPy
- Automatic fallback to optimized NumPy vectorized operations
- Batch frame processing for maximum throughput
๐ Secure Key Management
- Cryptographically secure random key generation
- PBKDF2-HMAC-SHA256 password-based key derivation (600K iterations, OWASP recommended)
- ECDH key exchange (SECP384R1) for secure key sharing over insecure channels
- Password-protected
.fortkeykey files (AES-GCM encrypted) - Key fingerprinting and HMAC verification
๐ฆ Custom File Format
.fortspyencrypted video format with structured binary header- Embedded metadata: resolution, FPS, frame count, encryption parameters
- HMAC-protected headers to detect tampering
- Streaming-compatible frame layout with length-prefixed chunks
๐ Project Structure
fort-spy/
โโโ fortspy/ # Main package
โ โโโ __init__.py
โ โโโ cli.py # Command-line interface
โ โโโ core/
โ โ โโโ __init__.py
โ โ โโโ encryptor.py # Frame encryption engine
โ โ โโโ decryptor.py # Real-time decryption engine
โ โ โโโ key_manager.py # Key generation & exchange
โ โโโ player/
โ โ โโโ __init__.py
โ โ โโโ fort_player.py # Dedicated video player
โ โโโ utils/
โ โโโ __init__.py
โ โโโ gpu_accelerator.py # GPU/OpenCL acceleration
โโโ tests/
โ โโโ __init__.py
โ โโโ test_fortspy.py # Comprehensive test suite
โโโ examples/
โ โโโ quick_start.py # Full pipeline demo
โ โโโ key_exchange.py # ECDH key exchange demo
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # GitHub Actions CI
โโโ setup.py
โโโ pyproject.toml
โโโ requirements.txt
โโโ requirements-dev.txt
โโโ LICENSE
โโโ .gitignore
โโโ README.md
๐ Installation
From Source
git clone https://github.com/your-username/fort-spy.git
cd fort-spy
pip install -e .
With GPU Support
# OpenCL (AMD/Intel/NVIDIA)
pip install -e ".[gpu-opencl]"
# CUDA (NVIDIA)
pip install -e ".[gpu-cuda]"
Development
pip install -e ".[dev]"
๐ Usage
CLI Commands
Fort Spy provides a full-featured command-line interface:
Encrypt a Video
# With auto-generated key (key printed to terminal)
fortspy encrypt -i video.mp4 -o secure.fortspy
# With password
fortspy encrypt -i video.mp4 -o secure.fortspy -p "my_strong_password"
# With specific key and mode
fortspy encrypt -i video.mp4 -o secure.fortspy --hex-key abcdef... --mode GCM --key-size 256
# Save key to protected file
fortspy encrypt -i video.mp4 -o secure.fortspy -p "password" --save-key my.fortkey
Decrypt a Video
# With key file
fortspy decrypt -i secure.fortspy -o output.mp4 --keyfile my.fortkey -p "password"
# With hex key
fortspy decrypt -i secure.fortspy -o output.mp4 --hex-key abcdef...
# Disable GPU acceleration
fortspy decrypt -i secure.fortspy -o output.mp4 --keyfile my.fortkey --no-gpu
Play Encrypted Video
# With key file (recommended)
fortspy play secure.fortspy --keyfile my.fortkey -p "password"
# With hex key and stats overlay
fortspy play secure.fortspy --hex-key abcdef... --stats
# Interactive (prompts for key)
fortspy play secure.fortspy
Player Controls:
| Key | Action |
|---|---|
Space |
Play / Pause |
Q / Esc |
Quit |
F |
Toggle Fullscreen |
S |
Toggle Stats Overlay |
+ / - |
Speed Up / Slow Down |
Generate Keys
# Generate and display a key
fortspy keygen
# Generate and save to protected file
fortspy keygen -o my.fortkey -p "file_password" --key-size 256
Inspect Encrypted Files
fortspy info secure.fortspy
Check GPU Status
fortspy gpu-info
Python API
Basic Encryption & Decryption
from fortspy import FortSpyEncryptor, FortSpyDecryptor, KeyManager
# Generate key
km = KeyManager(256)
key = km.generate_key()
# Encrypt
encryptor = FortSpyEncryptor(key=key, mode="CTR", key_size=256)
metadata = encryptor.encrypt_video("input.mp4", "encrypted.fortspy")
print(f"Encrypted {metadata['total_frames']} frames")
# Decrypt
decryptor = FortSpyDecryptor(key=key, use_gpu=True)
result = decryptor.decrypt_to_video("encrypted.fortspy", "output.mp4")
print(f"Decrypted at {result['effective_fps']:.1f} FPS")
Password-Based Encryption
from fortspy import FortSpyEncryptor, KeyManager
km = KeyManager(256)
key, salt = km.derive_key_from_password("my_secret_password")
# Save the salt โ you'll need it for decryption!
encryptor = FortSpyEncryptor(key=key, mode="CTR")
encryptor.encrypt_video("input.mp4", "encrypted.fortspy")
ECDH Key Exchange
from fortspy import KeyManager
# Alice
alice = KeyManager(256)
alice_pub = alice.generate_ecdh_keypair()
alice_pem = alice.export_public_key_pem()
# Bob
bob = KeyManager(256)
bob_pub = bob.generate_ecdh_keypair()
bob_pem = bob.export_public_key_pem()
# Exchange public keys, then derive shared secret
alice_shared = alice.derive_shared_key(bob.import_public_key_pem(bob_pem))
bob_shared = bob.derive_shared_key(alice.import_public_key_pem(alice_pem))
assert alice_shared == bob_shared # Same key on both sides!
Streaming Decryption
from fortspy import FortSpyDecryptor
decryptor = FortSpyDecryptor(key=key, use_gpu=True)
for frame, idx in decryptor.decrypt_video_stream("encrypted.fortspy"):
# Process each decrypted frame as numpy array
process(frame)
Fort Spy Player (Programmatic)
from fortspy import FortSpyPlayer
player = FortSpyPlayer(key=key, use_gpu=True, show_stats=True)
player.play("encrypted.fortspy")
# Headless mode (no GUI)
result = player.play_headless("encrypted.fortspy", output_path="decrypted.mp4")
๐ Architecture
Encryption Pipeline
Input Video (MP4/AVI/MKV)
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frame Extraction โ OpenCV reads each frame
โ (BGR pixel array) โ as numpy array (HรWร3)
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pixel Serialization โ frame.tobytes() โ raw RGB
โ (H ร W ร 3 bytes) โ bytes stream
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AES Encryption โ Per-frame nonce (CTR mode)
โ (CTR/CBC/GCM) โ or IV reuse (CBC/GCM)
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frame Packaging โ 4-byte length prefix +
โ (length-prefixed) โ ciphertext [+ GCM tag]
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ .fortspy File โ Header (HMAC) + encrypted
โ (binary format) โ frame sequence
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
Real-Time Decryption (Player)
.fortspy File
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Header Validation โ HMAC verification +
โ (key check) โ metadata extraction
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โโโโโโโโโโดโโโโโโโโโโ
โ Decrypt Thread โ Background pre-decryption
โ (producer) โ into frame buffer
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Frame Buffer โ Thread-safe queue (30-60
โ (queue) โ frames ahead)
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโดโโโโโโโโโโ
โ Display Thread โ Timing-controlled frame
โ (consumer) โ display + overlays
โโโโโโโโโโฌโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ GPU Post-proc โ Optional OpenCL/CUDA
โ + Rendering โ pixel processing
โโโโโโโโโโโโโโโโโโโ
๐งช Testing
# Run all tests
pytest tests/ -v
# With coverage
pytest tests/ -v --cov=fortspy --cov-report=html
# Run specific test class
pytest tests/test_fortspy.py::TestFrameEncryption -v
๐ง Supported Formats
Input Video Formats
Any format supported by OpenCV/FFmpeg: MP4, AVI, MKV, MOV, WebM, FLV, WMV
Encryption Modes
| Mode | Description | Best For |
|---|---|---|
| CTR (default) | Counter mode, parallelizable, no padding needed | General use, best performance |
| CBC | Cipher Block Chaining, requires padding | Legacy compatibility |
| GCM | Galois/Counter Mode with authentication tag | Maximum security (tamper detection) |
๐ Performance
Benchmark on a 1080p video (1920ร1080, 30fps):
| Operation | CPU Only | GPU (OpenCL) | GPU (CUDA) |
|---|---|---|---|
| Encrypt | ~45 FPS | โ | โ |
| Decrypt | ~50 FPS | ~120 FPS | ~180 FPS |
| Player | ~48 FPS | ~110 FPS | ~165 FPS |
Results vary by hardware. GPU acceleration primarily benefits decryption and playback.
๐ Security Considerations
- AES-256-CTR is the default mode providing strong encryption with excellent performance
- AES-256-GCM provides authenticated encryption (recommended for tamper detection)
- Per-frame nonce derivation in CTR mode prevents nonce reuse across frames
- PBKDF2 with 600,000 iterations follows OWASP 2023 recommendations
- ECDH over SECP384R1 provides ~192-bit security for key exchange
- Key files are encrypted with AES-GCM when password-protected
- Header HMAC detects key mismatches before attempting frame decryption
โ ๏ธ Important: This is an educational/research project. For production DRM or content protection, consider established solutions alongside Fort Spy's encryption layer.
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run the tests (
pytest tests/ -v) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
๐บ Roadmap
- Hardware-accelerated AES via AES-NI intrinsics
- WebAssembly player for browser-based playback
- Audio track encryption support
- Selective region-of-interest encryption
- Multi-key access control (encrypt once, multiple authorized viewers)
- Streaming protocol support (RTSP/HLS encrypted transport)
- Watermarking integration for forensic tracking
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fortspy-1.0.0.tar.gz.
File metadata
- Download URL: fortspy-1.0.0.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66c8b6446695f22259b4147cc3be153b28f472482fdb450391fdd0c5c89c5733
|
|
| MD5 |
09638e3db48bc7546576f751cb749a37
|
|
| BLAKE2b-256 |
b1f7b9433881b7b4bc9485e94c754e699e94180656334390003bb243b1ee09ff
|
File details
Details for the file fortspy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fortspy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f4d5bf23b62cab5165b6ab801ed8cf2446341c66702a74ae988dbc49fcc95c2
|
|
| MD5 |
c7654d44087f7150ab8016c6962e682a
|
|
| BLAKE2b-256 |
a6fd78e372aa3944cc17ec741e7e9a4b5e5acadec856af321409fbba1127100e
|