Skip to main content

Pixel-level AES video encryption with real-time GPU-accelerated decryption

Project description

๐Ÿ”’ Fort Spy

Pixel-Level Video Encryption & Real-Time Decryption Technology

License: MIT Python 3.8+ CI

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 .fortkey key files (AES-GCM encrypted)
  • Key fingerprinting and HMAC verification

๐Ÿ“ฆ Custom File Format

  • .fortspy encrypted 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run the tests (pytest tests/ -v)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. 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


Download files

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

Source Distribution

fortspy-1.0.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

fortspy-1.0.0-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

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

Hashes for fortspy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 66c8b6446695f22259b4147cc3be153b28f472482fdb450391fdd0c5c89c5733
MD5 09638e3db48bc7546576f751cb749a37
BLAKE2b-256 b1f7b9433881b7b4bc9485e94c754e699e94180656334390003bb243b1ee09ff

See more details on using hashes here.

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

Hashes for fortspy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4d5bf23b62cab5165b6ab801ed8cf2446341c66702a74ae988dbc49fcc95c2
MD5 c7654d44087f7150ab8016c6962e682a
BLAKE2b-256 a6fd78e372aa3944cc17ec741e7e9a4b5e5acadec856af321409fbba1127100e

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