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.
Maintainers
Details
github.com/CodeLieutenant/laravel-crypto
Fund package maintenance!
https://github.com/CodeLieutenant”>
CodeLieutenant
[Installs](/packages/codelieutenant/laravel-crypto/stats):
0 [Dependents](/packages/codelieutenant/laravel-crypto/dependents?order_by=downloads):
0
[Suggesters](/packages/codelieutenant/laravel-crypto/suggesters):
0
[Security](/packages/codelieutenant/laravel-crypto/advisories):
0
Stars:
17
Watchers:
2
Forks:
1
Open Issues:
8
Requires
– php: >=8.1
[ext-sodium](/providers/ext-sodium): * [illuminate/collections](/packages/illuminate/collections): ^8|^9|^10 [illuminate/config](/packages/illuminate/config): ^8|^9|^10 [illuminate/contracts](/packages/illuminate/contracts): ^8|^9|^10 [illuminate/encryption](/packages/illuminate/encryption): ^8|^9|^10 [illuminate/hashing](/packages/illuminate/hashing): ^8|^9|^10 [illuminate/support](/packages/illuminate/support): ^8|^9|^10
Requires (Dev)
[orchestra/testbench](/packages/orchestra/testbench): ^8.21 [pestphp/pest](/packages/pestphp/pest): ^2.34 [pestphp/pest-plugin-laravel](/packages/pestphp/pest-plugin-laravel): ^2.3 [phpbench/phpbench](/packages/phpbench/phpbench): ^1.2
Suggests
– ext-igbinary: Required for Igbinary Serializer
– ext-json: Required for Json Serializer
– ext-msgpack: Required for MessagePack Serializer
This package is auto-updated.
Last update: 2024-02-27 20:12:23 UTC
README
What’s Laravel Crypto and why should I use it?
Laravel Crypto is a library that provides easy to use API for most common cryptographic functions.It is designed to be easy to use and secure.It uses the best and most secure algorithms available today.
Laravel’s default encryption is secure, but it is slow.Laravel Crypto provides faster and more secure algorithms for
encryption and hashing.
It’s drop in replacement for Laravel’s
EncryptionServiceProvider and it uses
libsodium under the hood.
As long as you use default laravel encryption, you don’t need to change anything in your code.
Getting started
Installing
composer require codelieutenant/laravel-crypto
Publishing config file
php artisan vendor:publish –provider=”CodeLieutenantLaravelCryptoServiceProvider”
Replacing Laravel’s EncryptionServiceProvider with LaravelCrypto’s ServiceProvider
In order to activate this package, you need to replace Laravel’s
EncryptionServiceProvider
with
LaravelCryptoServiceProvider.
In
config/app.php replace
IlluminateEncryptionEncryptionServiceProvider::class
with
CodeLieutenantLaravelCryptoServiceProvider::class
Depending on the laravel version you are using, you can do it in two ways.
Laravel 9.0 and above:
use CodeLieutenantLaravelCryptoServiceProvider as LaravelCryptoServiceProvider; use IlluminateEncryptionEncryptionServiceProvider as LaravelEncryptionServiceProvider; // …’providers’ => ServiceProvider::defaultProviders() + ->replace([ + LaravelEncryptionServiceProvider::class => LaravelCryptoServiceProvider::class, + ]) ->merge([ // …]) ->toArray(), // …
Laravel 8.0:
use CodeLieutenantLaravelCryptoServiceProvider as LaravelCryptoServiceProvider; ‘providers’ => [ // …- IlluminateEncryptionEncryptionServiceProvider::class, + LaravelCryptoServiceProvider::class, // …],
Configuration
In order to use Laravel Crypto, you need to change
cipher in the
config/app.php file.
Possible values:
Unique to Laravel Crypto:
– Sodium_AES256GCM
– Sodium_XChaCha20Poly1305
– Sodium_AEGIS128 (Planned on php8.4)
– Sodium_AEGIS256 (Planned on php8.4)
Coming from Laravel Encryption (supported as LaravelCrypto falls back to EncryptionServiceProvider implementation):
– AES-256-GCM
– AES-128-GCM
– AES-256-CBC (default)
– AES-128-CBC
‘cipher’ => ‘Sodium_AES256GCM’,
Generating Keys
For encryption Laravel command
php artisan key:generate is good and can be used, but since this package
can be used for hashing and signing the data, command for generating keys is provided.
php artisan crypto:keys
It generates backwards compatible keys for laravel
cipher configuration and keys for
Sodium algorithms.
There are multiple option for this command, you can check them by running
php artisan crypto:keys –help,
so this command can be used as a drop in replacement for
key:generate.
Using in existing laravel project
This package does not provide backward compatibility with Laravel’s default encryption (if configuration is changed).
If you want to use Laravel Crypto in an existing project, you need to re-encrypt all your data..