Git Product home page Git Product logo

laravel-model-encrypter's Introduction

Laravel Db Encrypter Package

This package was created to encrypt and decrypt values of Eloquent model attributes.

Key features

  • Encrypt, decrypt values stored in database fields
  • Using standard Laravel's Crypt service
  • Easy configuration

Requirements

  • Laravel: 6.0 and up
  • PHP: 7.1 and newer

Database schema

Encrypted values are stored as plain text so in most cases takes up more spaces then unencrypted one. Recommendation is to alter table column to TEXT type. If you want use VARCHAR or CHAR column type still you need to check if encrypted value fit.

Note:

Do not worry if you have current data in your database not encrypted and added column to $encryptable - they will return as is.
On save values will be encrypted and everything will work fine.

Installation

Via Composer command line:

$ composer require rahulshibu/laravel-model-encrypter

Usage

  1. Use the LaravelModelEncrypter\Traits\DBEncryptor trait in any Eloquent model that you wish to use encryption
  2. Define a protected $encryptable array containing a list of the encrypted attributes.
  3. Define the encryption key in .env file. Default encrption key will be empty.

For example:

Model

    
    use LaravelModelEncrypter\Traits\DBEncryptor;

    class Client extends Eloquent {
        use DBEncryptor;
       
        /** @var array The attributes that should be encrypted/decrypted */
        protected $encryptable = [
            'id_number', 
            'email',
        ];
    }

ENV

ENCRYPT_KEY=abcd1234
  1. You can use Laravel's original $casts to cast decrypted values

License

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

laravel-model-encrypter's People

Contributors

itsrahul-ab avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.