A modern, Laravel-aware PHP code obfuscator that secures your packages without breaking framework compatibility.
- Laravel-Aware: Intelligently preserves Laravel framework compatibility
- Selective Obfuscation: Target specific namespaces/packages while preserving third-party dependencies
- Modern Architecture: Built with PHP 8.3+, Composer, and Symfony Console
- Smart Analysis: Preview what will be obfuscated before making changes
- Incremental Processing: Only re-obfuscate changed files
- Flexible Configuration: YAML-based configuration with environment support
Install via Composer:
composer require diviky/secureOr download the PHAR:
wget https://github.com/diviky/secure/releases/latest/download/secure.phar
chmod +x secure.phar
sudo mv secure.phar /usr/local/bin/secure-
Initialize configuration:
secure init --laravel
-
Analyze your project:
secure analyze --detailed
-
Obfuscate your code:
secure obfuscate
The tool uses YAML configuration files. Here's an example for a Laravel project:
project:
type: laravel
name: my-laravel-app
version: 1.0.0
obfuscation:
variables: true
functions: true
classes: true
methods: true
properties: true
constants: true
namespaces: false # Keep namespaces for Laravel autoloading
strings: false # Careful with Laravel translations
control_structures: true
shuffle_statements: false
scope:
include_paths:
- app/
- packages/
exclude_paths:
- vendor/
- tests/
- storage/
- bootstrap/cache/
include_extensions:
- php
preserve_namespaces:
- Illuminate\
- Laravel\
preserve_classes:
- Model
- Controller
- Middleware
- ServiceProvider
preserve_methods:
- boot
- register
- handle
- render
output:
directory: dist/
preserve_structure: true
add_header: true
strip_comments: true
strip_whitespace: true
security:
scramble_mode: identifier
scramble_length: 8
add_dummy_code: false
randomize_order: falseInitialize configuration for your project.
Options:
--laravel: Optimize for Laravel projects--package: Optimize for package development--force: Overwrite existing configuration
Examples:
secure init --laravel
secure init --package
secure init --forceAnalyze your project and preview obfuscation.
Options:
--config: Path to configuration file--detailed: Show detailed analysis--export: Export analysis (json|yaml|csv)
Examples:
secure analyze
secure analyze --detailed
secure analyze --export jsonObfuscate your code.
Options:
--config: Path to configuration file--dry-run: Preview without making changes--force: Overwrite existing output--backup: Create backup before obfuscation--watch: Watch for changes and auto-obfuscate
Examples:
secure obfuscate --dry-run
secure obfuscate --backup
secure obfuscate --watchThe tool automatically detects Laravel projects and:
- Preserves framework namespaces (
Illuminate\,Laravel\) - Keeps essential class types (
Model,Controller, etc.) - Maintains service provider methods (
boot,register) - Avoids breaking autoloading
When developing packages:
secure init --packageThis optimizes configuration for package development by:
- Focusing on
src/directory - Preserving public APIs
- Maintaining PSR-4 autoloading compatibility
β Safe to obfuscate:
- Private/protected methods and properties
- Internal business logic
- Helper functions
- Private classes
β Avoid obfuscating:
- Public APIs used by other packages
- Laravel framework interfaces
- Database migrations
- Configuration files
-
Preserve Service Provider Methods:
preserve_methods: - boot - register - provides
-
Keep Model Relationships Readable:
preserve_methods: - belongsTo - hasMany - hasOne - belongsToMany
-
Maintain Artisan Commands:
preserve_classes: - Command preserve_methods: - handle - configure
Create different configs for different environments:
secure.dev.yaml # Development
secure.staging.yaml # Staging
secure.prod.yaml # ProductionUse with:
secure obfuscate --config secure.prod.yamlsecurity:
scramble_mode: identifier # identifier, hexadecimal, numeric
scramble_length: 12 # Longer names = better securityFor large projects:
obfuscation:
shuffle_statements: false # Disable for better performance
scope:
exclude_paths:
- vendor/ # Never obfuscate dependencies
- storage/ # Skip cache/logs
- node_modules/ # Skip frontend assetsAutoloading Problems:
- Ensure
preserve_namespacesincludes your PSR-4 namespaces - Don't obfuscate class names used in
composer.jsonautoload
Laravel Errors:
- Add framework classes to
preserve_classes - Include essential methods in
preserve_methods
Performance Issues:
- Disable
shuffle_statementsfor large codebases - Use
exclude_pathsto skip unnecessary directories
-
Use analyze first:
secure analyze --detailed --export csv
-
Test with dry-run:
secure obfuscate --dry-run
-
Enable verbose output:
secure obfuscate -v
- PHP 8.3+
- Composer
- ext-mbstring
git clone https://github.com/diviky/secure.git
cd secure
composer install
./bin/secure --versioncomposer test
composer test-coveragecomposer psalmMIT License. See LICENSE for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- π Documentation
- π Issue Tracker
- π¬ Discussions