Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Laravel package for persisting encrypted Model properties, providing decryption when accessed.

License

NotificationsYou must be signed in to change notification settings

sagalbot/encryptable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Laravel 5 package that allows you to store Eloquent model properties encrypted in your database, and automatically decrypts them when you need to access them.

example

Install

composer require sagalbot/encryptable

Usage

This package is really just a simple trait and property that you can add to your Eloquent models. Usage is simple:

  1. Before using Laravel's encrypter, you must set a key option in your config/app.php configuration file.

    artisan key:generate

    note:If you already haveAPP_KEY set in your.env, you should skip this step.

  2. Use theSagalbot\Encryptable\Encryptable trait:

    use \Sagalbot\Encryptable\Encryptable;
  3. Set the$encryptable array on your Model.

    protected$encryptable = ['my_encrypted_property'];
  4. That's it! Here's a complete example:

    <?phpnamespaceApp;useIlluminate\Database\Eloquent\Model;useSagalbot\Encryptable\Encryptable;class MyEncryptedModelextends Model{use Encryptable;/**     * The attributes that should be encrypted when stored.     *     * @var array     */protected$encryptable = ['my_encrypted_property','another_secret' ];}

Encryption Options

By default, the package uses the globalencrypt() anddecrypt() Laravel functions, which are just aliases to resolve theIlluminate\Encryption\Encrypter::class out of the container. Laravel's encrypter uses OpenSSL to provide AES-256 and AES-128 encryption, which you can read more about at theLaravel Docs.

If you need to adjust how a specific model encrypts and decrypts its properties, you can override thedecryptAttribute andencryptAttribute methods on your model:

/** * @param $value */protectedfunctionencryptAttribute($value){//  encrypt the value}/** * @param $value */protectedfunctiondecryptAttribute($value){//  decrypt the value}

Keep It Secret, Keep It Safe

Keep it Secret, Keep it Safe

Don't lose your encryption key - you can't decrypt your stored data without it.

About

Laravel package for persisting encrypted Model properties, providing decryption when accessed.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp