Download the PHP package ercsctt/laravel-file-encryption without Composer
On this page you can find all versions of the php package ercsctt/laravel-file-encryption. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ercsctt/laravel-file-encryption
More information about ercsctt/laravel-file-encryption
Files in ercsctt/laravel-file-encryption
Package laravel-file-encryption
Short Description Secure file encryption and decryption for Laravel applications
License MIT
Homepage https://github.com/ercsctt/laravel-file-encryption
Informations about the package laravel-file-encryption
Laravel File Encryption
A robust file encryption package for Laravel using AES-256-GCM authenticated encryption. Designed for secure, efficient encryption and decryption of files of any size with streaming support for memory-efficient processing of large files.
Features
- AES-256-GCM encryption - Industry-standard authenticated encryption
- Streaming support - Process files of any size with minimal memory usage
- Key rotation - Seamlessly rotate encryption keys without downtime
- Artisan commands - Encrypt and decrypt files from the command line
- Facade and helper - Convenient ways to use the package
Requirements
- PHP 8.2 or higher
- Laravel 11.0 or higher
- OpenSSL PHP extension
Installation
Install the package via Composer:
The package will automatically register its service provider.
Configuration
Publish the configuration file:
This will create a config/file-encryption.php file.
Environment Variables
Add the following to your .env file:
Generate a key using:
Optional configuration:
Usage
Using the Facade
Using the Helper Function
Direct Instantiation
Artisan Commands
Encrypt Command
| Options: | Option | Description |
|---|---|---|
--key= |
Encryption key (base64-encoded). Uses configured key if not provided | |
-R, --recursive |
Recursively encrypt all files in a directory | |
--force |
Skip confirmation prompts | |
--chunk-size=65536 |
Chunk size in bytes for streaming | |
--prune |
Delete original files after successful encryption |
Examples:
Decrypt Command
| Options: | Option | Description |
|---|---|---|
--key= |
Decryption key (base64-encoded) | |
-R, --recursive |
Recursively decrypt all .enc files in a directory | |
--force |
Skip confirmation prompts | |
--keep |
Keep encrypted files after successful decryption | |
--output= |
Custom output path for decrypted file | |
--scan |
Scan entire project for encrypted (.enc) files |
Examples:
Common Workflows
Encrypt sensitive uploads for storage:
Decrypt files for processing, then re-encrypt:
Find and decrypt all encrypted files in a project:
Migrate to a new encryption key:
Streaming Large Files
For large files, use decryptedStream() for memory-efficient processing:
Progress Callbacks
Monitor progress when processing large files:
Key Rotation
When you need to rotate your encryption key:
-
Generate a new key:
-
Update your
.envfile: -
The package will automatically try previous keys when decrypting files encrypted with old keys.
- Programmatically configure previous keys:
Security Features
- AES-256-GCM - Provides both confidentiality and authenticity
- Unique nonce per chunk - Each chunk uses a unique 12-byte nonce derived from base nonce XORed with chunk index
- Authentication tag - 16-byte GCM authentication tag per chunk prevents tampering
- Chunk index in AAD - Additional authenticated data includes chunk index to prevent reordering attacks
- Header HMAC - 12-byte truncated HMAC-SHA256 protects header integrity
- Constant-time comparisons - Uses
hash_equals()to prevent timing attacks - Secure key handling - Keys marked with
#[\SensitiveParameter]attribute
File Format
Encrypted files use the following binary format:
Error Handling
The package throws specific exceptions for different error conditions:
Key Validation
Testing
Run the test suite:
Or with PHPUnit directly:
API Reference
FileEncrypter Methods
| Method | Signature | Description |
|---|---|---|
encryptFile |
(string $source, ?string $dest = null, ?callable $progress = null): void |
Encrypt a file. Destination defaults to $source.enc |
decryptFile |
(string $source, ?string $dest = null, ?callable $progress = null): void |
Decrypt a file. Destination defaults to source without .enc |
decryptedContents |
(string $path): string |
Return entire decrypted file contents as string |
decryptedStream |
(string $path, callable $callback): void |
Stream decrypted chunks through callback |
isEncrypted |
(string $path): bool |
Check if file has encryption magic bytes |
previousKeys |
(array $keys): static |
Set previous keys for key rotation (fluent) |
getKey |
(): string |
Get primary encryption key |
getChunkSize |
(): int |
Get configured chunk size |
getAllKeys |
(): array |
Get all keys (primary + previous) |
License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-file-encryption with dependencies
ext-openssl Version *
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/console Version ^11.0|^12.0|^13.0
illuminate/filesystem Version ^11.0|^12.0|^13.0
symfony/finder Version ^7.0|^8.0