macellan/laravel-encryption

Provides flexible data encryption adapter for Laravel.

1.0.03 2021-10-18 19:46 UTC

This package is auto-updated.

Last update: 2024-04-19 01:12:02 UTC


README

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);
);