sagalbot/encryptable
最新稳定版本:v1.0.1
Composer 安装命令:
composer require sagalbot/encryptable
包简介
Allows you to store Eloquent properties encrypted in your database, and automatically decrypt when accessed.
README 文档
README
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.
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:
-
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 have
APP_KEYset in your.env, you should skip this step. -
Use the
Sagalbot\Encryptable\Encryptabletrait:use \Sagalbot\Encryptable\Encryptable;
-
Set the
$encryptablearray on your Model.protected $encryptable = ['my_encrypted_property'];
-
That's it! Here's a complete example:
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Sagalbot\Encryptable\Encryptable; class MyEncryptedModel extends 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 global encrypt() and decrypt() Laravel functions, which are just aliases to resolve the Illuminate\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 the Laravel Docs.
If you need to adjust how a specific model encrypts and decrypts its properties, you can override the decryptAttribute and encryptAttribute methods on your model:
/** * @param $value */ protected function encryptAttribute($value) { // encrypt the value } /** * @param $value */ protected function decryptAttribute($value) { // decrypt the value }
Keep It Secret, Keep It Safe
Don't lose your encryption key - you can't decrypt your stored data without it.
统计信息
- 总下载量: 52.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-18
