crisjohn02 / encrypter
列加密器
dev-master
2019-08-06 13:57 UTC
Requires
- php: ^7.1.3
This package is auto-updated.
Last update: 2024-09-07 01:53:25 UTC
README
此包的主要内容是什么?
此包会在存储时自动加密 eloquent,在检索时自动解密。这在有人非法下载数据库并使数据失效时非常有用。盐值是用户特定的,因此所有数据不能仅通过一个盐值解密。请注意,一旦丢失盐值,加密数据将无法再次解密,因此使用此包时请小心。
安装
composer require crisjohn02/encrypter
使用方法
创建带有 salt
列的用户表。
Schema::create('users', function(Blueprint $table) { $table->string('salt'); });
为了自动创建盐值,将特性 HasSalt
添加到您的 User 模型中
<?php namespace App\YourNameSpace; use Illuminate\Database\Eloquent\Model; use Crisjohn02\Encrypter\Traits\HasSalt; class User extends Model { use HasSalt; }
在您的 eloquent 模型中添加特性 Encryptable
<?php namespace App\YourNameSpace; use Illuminate\Database\Eloquent\Model; use Crisjohn02\Encrypter\Traits\Encryptable; class Post extends Model { use Encryptable; //Specify the encryptable columns protected $encryptables = [ 'title', 'user_id' ]; }
您还可以使用 HasUuid
特性,并确保您的模型有 uuid
列
<?php namespace App\YourNameSpace; use Illuminate\Database\Eloquent\Model; use Crisjohn02\Encrypter\Traits\HasUuid; class Post extends Model { use HasUuid; }
限制
不要在用户模型中使用 Encryptable
特性,这将在创建新用户时引发错误。