Looking to hire Laravel developers? Try LaraJobs

laravel-encryption maintained by macellan

Description
Provides flexible data encryption adapter for Laravel.
Last update
2021/10/18 21:46 (dev-main)
License
Downloads
204

Comments
comments powered by Disqus

Laravel Encryption

Provides flexible data encryption adapter for Laravel. 2-step encryption is available. Adapter settings are encrypted with "encryption_key". Data is encrypted with adapters.

Requirement PHP 7.4+.

Installation

  • Install Package
    composer req macellan/laravel-encryption
    
  • Preparing Database & Config File
    php artisan vendor:publish --tag="encryption"
    
  • Run Migrations
    php artisan migrate
    
  • Default Configuration: config/encryption.php
    <?php
    
    return [
        /*
        |--------------------------------------------------------------------------
        | Encrypt Adapter Options
        |--------------------------------------------------------------------------
        */
        'options_encrypt' => true,
    
        /*
        |--------------------------------------------------------------------------
        | Options Encryption Key.
        |--------------------------------------------------------------------------
        */
        'encryption_key' => env('ENCRYPTION_KEY'),
    
        /*
        |--------------------------------------------------------------------------
        | Encryption Adapters
        |--------------------------------------------------------------------------
        */
        'adapters' => [
            \Macellan\LaravelEncryption\Adapters\LocalAdapter::class,
        ],
    ];
    

Provider Commands

  • List Provider:
    php artisan encryption:list
    
  • Create Provider:
    php artisan encryption:create
    
  • Edit Provider:
    php artisan encryption:edit
    
  • List Provider:
    php artisan encryption:remove
    
  • List Provider:
    php artisan encryption:key:generate
    

Usage

<?php
$data = [1,2,3];

// Data Encrypt-Decrypt
$encrypt = app('encryption')->encrypt($data);
$decrypt = app('encryption')->decrypt($encrypt)->data();

// Custom Encryption Provider
$decrypt = app('encryption')->decrypt(
    new CryptedData(EncryptionProvider $provider, $cryptedData);
);