New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jfelixstudio/laravel-mysql-encrypt

Laravel 5.x | 6.x | 7.x | 8.x Database encryption mysql side
3,576 1
Install
composer require jfelixstudio/laravel-mysql-encrypt
Latest Version:1.4
PHP:^7.3|^8.0
Laravel:5 – 9
License:MIT
Last Updated:Mar 21, 2022
Links: GitHub  ·  Packagist
Maintainer: jfuenzalida

Laravel/Lumen MySql AES Encrypt/Decrypt

Latest Stable Version Latest Unstable Version Total Downloads License

Laravel/Lumen database encryption at database side using native AES_DECRYPT and AES_ENCRYPT functions. Automatically encrypt and decrypt fields in your Models.

Install

1. Composer

composer require JfelixStudio/laravel-mysql-encrypt

2. Publish config (optional)

Laravel

php artisan vendor:publish --provider="JfelixStudio\MysqlEncrypt\Providers\LaravelServiceProvider"

Lumen

mkdir -p config
cp vendor/JfelixStudio/laravel-mysql-encrypt/config/config.php config/mysql-encrypt.php

3. Configure Provider

Laravel

  • For Laravel 5.5 or later, the service provider is automatically loaded, skip this step.

  • For Laravel 5.4 or earlier, add the following to config/app.php:

'providers' => array(
    JfelixStudio\\MysqlEncrypt\\Providers\\LaravelServiceProvider::class
);

Lumen

  • For Lumen, add the following to bootstrap/app.php:
$app->register(JfelixStudio\MysqlEncrypt\Providers\LumenServiceProvider::class);

4. Set encryption key in .env file

APP_AESENCRYPT_KEY=yourencryptionkey

Update Models

<?php

namespace App;

use JfelixStudio\MysqlEncrypt\Traits\Encryptable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Encryptable; // <-- 1. Include trait

    protected $encryptable = [ // <-- 2. Include columns to be encrypted
        'email',
        'first_name',
        'last_name',
        'telephone',
    ];
}

Validators

unique_encrypted

unique_encrypted:<table>,<field(optional)>

exists_encrypted

exists_encrypted:<table>,<field(optional)>

Scopes

Custom Local scopes available:

whereEncrypted whereInEncrypted whereNotEncrypted orWhereEncrypted orWhereNotEncrypted orderByEncrypted

Global scope DecryptSelectScope automatically booted in models using Encryptable trait.

Schema columns to support encrypted data

Schema::create('users', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

// Once the table has been created, use ALTER TABLE to create VARBINARY
// or BLOB types to store encrypted data.
DB::statement('ALTER TABLE `users` ADD `first_name` VARBINARY(300)');
DB::statement('ALTER TABLE `users` ADD `last_name` VARBINARY(300)');
DB::statement('ALTER TABLE `users` ADD `email` VARBINARY(300)');
DB::statement('ALTER TABLE `users` ADD `telephone` VARBINARY(50)');

License

The MIT License (MIT). Please see License File for more information.

Related Packages

tapanderasari/laravel-mysql-encrypt

Laravel Database encryption mysql side

1,969 3
chr15k/laravel-mysql-encrypt

Laravel database encryption using native MySQL functions

10,863 11
codezero/encrypter

Encrypt and decrypt strings in PHP.

100,316 2
valorin/random

Random is a simple helper package designed to make it easy to generate a range o...

413,065 233
php
awssat/laravel-sync-migration

Laravel tool helps to sync migrations without refreshing the database

23,815 108

Version History

Version Released PHP Laravel License
1.4 ^7.3|^8.0 ^5.0|^6.0|^7.0|^8.0|^9.0 MIT
1.3.2 ^7.3|^8.0 ^5.0|^6.0|^7.0|^8.0 MIT
1.3.1 ^7.3|^8.0 ^5.0|^6.0|^7.0|^8.0 MIT
1.3 ^7.3|^8.0 ^5.0|^6.0|^7.0|^8.0 MIT
1.2.2 ^7.3|^8.0 ^5.0|^6.0|^7.0|^8.0 MIT