Skip to main content

Python Source Code Encryption Tool - Enterprise-grade protection for your Python source code

Project description

STXDefender - Python Source Code Encryption Tool

STXDefender provides enterprise-grade protection for your Python source code using AES-256-GCM encryption. Safeguard your intellectual property with military-grade cryptography, license management, and flexible access control.

Features

  • ๐Ÿ”’ AES-256-GCM Encryption - Industry-standard authenticated encryption
  • ๐Ÿ”‘ License Activation - Secure token-based activation system with online validation
  • โฑ๏ธ Enforced Expiry (TTL) - Control access with customizable expiration times
  • ๐Ÿ” Custom Password Support - Use your own passwords or auto-generated secure keys
  • ๐Ÿ†“ Trial Mode - Test the tool with 24-hour encrypted file limits
  • ๐Ÿš€ Direct Execution - Run encrypted .pye files directly with Python
  • ๐Ÿ’ป Simple CLI - Intuitive commands: activate, validate, encrypt
  • ๐Ÿ“Š Web Dashboard - Manage licenses, tokens, and subscriptions through a modern web interface

Installation

Install from PyPI (Recommended)

pip install stxdefender

After installation, the stxdefender command will be available globally.

Install from Source

If you want to install from the source code:

# Navigate to project directory
cd "path/to/sourcedefender remake"

# Install in editable mode
pip install -e .

Quick Setup (Windows)

Automated setup with server:

  1. Double-click setup_and_run.bat

    • Installs all dependencies
    • Sets up the CLI tool
    • Starts the backend server
  2. Or use START.bat for a quick start (assumes dependencies are installed)

  3. Or use INSTALL.bat to just install dependencies without starting

Quick Setup (Linux/Mac)

chmod +x setup_and_run.sh
./setup_and_run.sh

Quick Start Guide

1. Start the Backend Server

If you installed from source and want to run your own server:

cd backend
python app.py

The server will start on http://localhost:5000

2. Create an Account

  1. Open your browser and go to http://localhost:5000
  2. Click "Sign up" and create an account
  3. Log in to access the dashboard

3. Generate an Activation Token

  1. In the dashboard, click "Generate New Token"
  2. Copy the token (you'll only see it once!)

4. Activate STXDefender

stxdefender activate --token YOUR_TOKEN_HERE

5. Validate Activation

stxdefender validate

6. Encrypt Your Python Files

# Basic encryption
stxdefender encrypt myapp.py

# With expiration (24 hours)
stxdefender encrypt --ttl=24h myapp.py

# With custom password
stxdefender encrypt --password=mysupersecret myapp.py

# Remove original file after encryption
stxdefender encrypt --remove myapp.py

This creates an encrypted .pye file (e.g., myapp.pye).

7. Run Encrypted Files

# Run encrypted file directly
python myapp.pye

# With custom password (if used during encryption)
export STXDEFENDER_PASSWORD="mysupersecret"
python myapp.pye

# On Unix/Linux/Mac, make executable and run directly
chmod +x myapp.pye
./myapp.pye

Command Reference

stxdefender activate --token <token>

Activate your license with a token obtained from the dashboard.

stxdefender activate --token 470a7f2e76ac11eb94390242ac130002

stxdefender validate

Check your current license activation status.

stxdefender validate

stxdefender encrypt [options] <file>

Encrypt a Python source file.

Options:

  • --remove - Remove the original file after encryption
  • --ttl=<time> - Set expiration time (e.g., 24h, 7d, 30m, 1w)
  • --password=<pass> - Use a custom password (otherwise auto-generated)

Examples:

# Basic encryption
stxdefender encrypt script.py

# With 24-hour expiration and remove original
stxdefender encrypt --remove --ttl=24h myapp.py

# With custom password
stxdefender encrypt --password=mysecret script.py

# Complex example
stxdefender encrypt --remove --ttl=7d --password=supersecret myapp.py

TTL (Time To Live) Format

The --ttl option accepts the following formats:

  • 30s - 30 seconds
  • 5m - 5 minutes
  • 24h - 24 hours
  • 7d - 7 days
  • 2w - 2 weeks
  • 365 - 365 seconds (numeric only = seconds)

Password Handling

Auto-generated Password

If no password is specified, STXDefender generates a secure random password. This password is embedded in the encrypted file, making the file self-contained and ready to run.

Custom Password

You can specify a custom password during encryption:

stxdefender encrypt --password=mypassword script.py

When running the encrypted file, set the password as an environment variable:

# Unix/Linux/Mac
export STXDEFENDER_PASSWORD="mypassword"
python script.pye

# Windows (Command Prompt)
set STXDEFENDER_PASSWORD=mypassword
python script.pye

# Windows (PowerShell)
$env:STXDEFENDER_PASSWORD="mypassword"
python script.pye

If the environment variable is not set, it will use the password embedded in the file (or the one you specified during encryption).

Trial Mode

Without a valid license activation, STXDefender operates in trial mode:

  • โœ… Encryption works normally
  • โš ๏ธ Maximum TTL is limited to 24 hours
  • โš ๏ธ A warning message is displayed

To remove trial limitations, activate with a valid token from the dashboard.

Project Structure

.
โ”œโ”€โ”€ backend/
โ”‚   โ””โ”€โ”€ app.py              # Flask backend API
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ index.html          # Landing page
โ”‚   โ”œโ”€โ”€ login.html          # Login/signup page
โ”‚   โ”œโ”€โ”€ dashboard.html      # User dashboard
โ”‚   โ”œโ”€โ”€ admin.html          # Admin dashboard
โ”‚   โ””โ”€โ”€ static/
โ”‚       โ”œโ”€โ”€ style.css       # Styles
โ”‚       โ”œโ”€โ”€ auth.js         # Auth page JavaScript
โ”‚       โ”œโ”€โ”€ dashboard.js    # Dashboard JavaScript
โ”‚       โ””โ”€โ”€ admin.js        # Admin panel JavaScript
โ”œโ”€โ”€ stxdefender.py          # Main CLI tool
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ setup.py               # Package setup for PyPI
โ””โ”€โ”€ README.md              # This file

Development

Running the Backend

Windows:

  • Use setup_and_run.bat (installs and runs)
  • Use START.bat (quick start)
  • Use run_server.bat (assumes dependencies installed)

Linux/Mac:

./setup_and_run.sh
# OR
cd backend
python3 app.py

The server runs on http://localhost:5000 by default.

Environment Variables

  • STXDEFENDER_API_URL - API endpoint URL (default: http://localhost:5000)
  • SECRET_KEY - Flask secret key (default: auto-generated)
  • STXDEFENDER_PASSWORD - Default password for encrypted files

Database

The backend uses SQLite by default (jsdefender.db for compatibility). For production deployments, consider using PostgreSQL or MySQL.

Security

STXDefender implements multiple layers of security:

  • Strong Encryption: AES-256-GCM authenticated encryption prevents tampering
  • Key Derivation: PBKDF2 with 200,000 iterations for key generation
  • Secure Tokens: Cryptographically secure random token generation
  • License Binding: System fingerprinting binds licenses to specific machines
  • Dual Validation: Both local and remote license validation
  • Password Security: Passwords are hashed using SHA-256 (bcrypt recommended for production)

Use Cases

  • Protect proprietary Python applications
  • Distribute encrypted scripts with expiration dates
  • Control access to sensitive code
  • License management for commercial software
  • Secure distribution of Python tools and utilities

License

This project is provided as-is for educational and development purposes.

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Support

For issues and questions, please open an issue on the project repository.

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

stxdefender-1.0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

stxdefender-1.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file stxdefender-1.0.1.tar.gz.

File metadata

  • Download URL: stxdefender-1.0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.5

File hashes

Hashes for stxdefender-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1c2c14cd94ceed1887198f8108fa30be50c641988841ee51ff21445d18974e94
MD5 c50bc19e144cf6e66a8d1a7a6c976c56
BLAKE2b-256 fa81cbf96b1cbbe263ae0d3c792f12a19cf18723a124584072b15d1dfaa11ee4

See more details on using hashes here.

File details

Details for the file stxdefender-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: stxdefender-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.5

File hashes

Hashes for stxdefender-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 82f569d7760f0805a878fcb8fdc2c0e6a4937d1ba4aad45c8319407801d6ca05
MD5 7087009b4a830747bc4944c324c8bb97
BLAKE2b-256 f74ddb2791ed1c06b02a70f4ad8c428626f5cf6a509e374a8b67679c7fcae197

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