Download the PHP package codelieutenant/laravel-crypto without Composer
On this page you can find all versions of the php package codelieutenant/laravel-crypto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codelieutenant/laravel-crypto
More information about codelieutenant/laravel-crypto
Files in codelieutenant/laravel-crypto
Package laravel-crypto
Short Description Laravel Crypto is a package that provides a simple and easy to use API for encrypting, decrypting, hashing, and signing data using the latest PHP and Laravel features.
License MIT
Informations about the package laravel-crypto
Laravel Crypto
Laravel Crypto provides a simple and easy-to-use API for encrypting, decrypting, hashing, and signing data using modern cryptographic algorithms powered by libsodium.
Why Laravel Crypto?
- Modern Algorithms: Support for XChaCha20-Poly1305, AES-256-GCM, AEGIS-128L, AEGIS-256, XSalsa20-Poly1305, Blake2b, and EdDSA.
- Per-User Encryption: Secure data using keys derived from and unique to each user, ensuring data privacy even if the
APP_KEYis compromised. - Performance: High-performance cryptographic operations utilizing hardware acceleration where available.
- Drop-in Replacement: Seamlessly replaces Laravel's default
EncryptionServiceProvider. - Comprehensive: Includes support for hashing, signing (symmetric and asymmetric), file encryption, Eloquent casting for encrypted files, and various data encoders (JSON, MessagePack, Igbinary).
Requirements
- PHP: 8.4 or higher
- Extensions:
ext-sodium - Laravel: 10.x, 11.x, or 12.x
Getting Started
1. Installation
2. Service Provider Registration
In order to activate the package, you need to replace Laravel's default EncryptionServiceProvider with CodeLieutenant\LaravelCrypto\ServiceProvider.
Laravel 11.x & 12.x
In bootstrap/providers.php, replace the default provider:
Laravel 10.x
In config/app.php, replace Illuminate\Encryption\EncryptionServiceProvider::class in the providers array:
3. Configuration
Publish the configuration file:
Update your cipher in config/app.php:
4. Generating Keys
Generate the necessary cryptographic keys:
This will update your .env file with the required keys and generate an EdDSA key pair in storage/keys/.
Usage Overview
Encryption
Uses the standard Laravel Crypt facade but with Sodium algorithms.
File Encryption
Securely encrypt large files using chunked streaming.
Hashing
High-performance hashing using Blake2b.
Signing
Symmetric (HMAC) and Asymmetric (EdDSA) signing.
Eloquent Casting
Store files securely by automatically encrypting and decrypting them on-the-fly via an Eloquent caster.
User Encryption
Securely encrypt user data using their own unique encryption key.
For more details on setting up and using per-user encryption, see the User Encryption documentation.
Performance
Benchmarks conducted on various data sizes (PHP 8.5.1, Sodium extension enabled) on a Macbook M4 Pro 48GB RAM.
1 KiB Payload
| Algorithm | Encryption | Decryption |
|---|---|---|
| Laravel AES-256-CBC | 8.09 μs | 9.98 μs |
| Laravel AES-256-GCM | 3.37 μs | 5.33 μs |
| Sodium AES-256-GCM | 2.39 μs | 2.58 μs |
| Sodium AEGIS-128L | 2.03 μs | 2.14 μs |
| Sodium AEGIS-256 | 2.06 μs | 2.27 μs |
| Sodium XChaCha20-Poly1305 | 3.41 μs | 3.58 μs |
32 KiB Payload
| Algorithm | Encryption | Decryption |
|---|---|---|
| Laravel AES-256-CBC | 151.01 μs | 181.81 μs |
| Laravel AES-256-GCM | 35.81 μs | 81.98 μs |
| Sodium AES-256-GCM | 26.93 μs | 29.22 μs |
| Sodium AEGIS-128L | 18.23 μs | 20.68 μs |
| Sodium AEGIS-256 | 18.86 μs | 21.82 μs |
| Sodium XChaCha20-Poly1305 | 58.40 μs | 60.90 μs |
1 MiB Payload
| Algorithm | Encryption | Decryption |
|---|---|---|
| Laravel AES-256-CBC | 5.02 ms | 7.57 ms |
| Laravel AES-256-GCM | 1.31 ms | 3.94 ms |
| Sodium AES-256-GCM | 1.11 ms | 1.88 ms |
| Sodium AEGIS-128L | 0.90 ms | 1.60 ms |
| Sodium AEGIS-256 | 0.82 ms | 1.65 ms |
| Sodium XChaCha20-Poly1305 | 2.21 ms | 2.90 ms |
Sodium-based algorithms provide more consistent performance and are significantly faster for decryption of large payloads compared to Laravel's default implementations. AEGIS algorithms offer top-tier performance on modern hardware.
Documentation
For detailed information, please refer to the following documentation:
- Console Commands
- Encryption
- User Encryption
- Hashing
- Signing
- Utilities (Encoders, Base64, Random)
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-crypto with dependencies
ext-openssl Version *
ext-sodium Version *
illuminate/collections Version ^10|^11|^12
illuminate/config Version ^10|^11|^12
illuminate/contracts Version ^10|^11|^12
illuminate/encryption Version ^10|^11|^12
illuminate/hashing Version ^10|^11|^12
illuminate/support Version ^10|^11|^12