gestazion/laravel-encryptable
Composer 安装命令:
composer require gestazion/laravel-encryptable
包简介
Laravel Encryptable
README 文档
README
Laravel Encryptable
This package allows you to anonymize sensitive data (like the name, surname and email address of a user) similarly to Laravel's Encryption feature, but still have the ability to make direct queries to the database. An example use case could be the need to make search queries through anonymized attributes.
This package currently supports MySQL and PostgreSQL databases.
Installation
You can install the package via composer:
composer require maize-tech/laravel-encryptable
You can publish the config file with:
php artisan vendor:publish --provider="Maize\Encryptable\EncryptableServiceProvider" --tag="encryptable-config"
This is the content of the published config file:
return [ /* |-------------------------------------------------------------------------- | Encryption key |-------------------------------------------------------------------------- | | The key used to encrypt data. | Once defined, never change it or encrypted data cannot be correctly decrypted. | */ 'key' => env('ENCRYPTION_KEY'), /* |-------------------------------------------------------------------------- | Encryption cipher |-------------------------------------------------------------------------- | | The cipher used to encrypt data. | Once defined, never change it or encrypted data cannot be correctly decrypted. | Default value is the cipher algorithm used by default in MySQL. | */ 'cipher' => env('ENCRYPTION_CIPHER', 'aes-128-ecb'), ];
Usage
Basic
To use the package, just add the Encryptable cast to all model attributes you want to anonymize.
<?php namespace App\Models; use Maize\Encryptable\Encryptable; use Illuminate\Database\Eloquent\Model; class User extends Model { protected $fillable = [ 'name', 'email', ]; protected $casts = [ 'name' => Encryptable::class, 'email' => Encryptable::class, ]; }
Once done, all values will be encrypted before being stored in the database, and decrypted when querying them via Eloquent.
Manually encrypt via PHP
use Maize\Encryptable\Encryption; $value = "your-decrypted-value"; $encrypted = Encryption::php()->encrypt($value); // returns the encrypted value
Manually decrypt via PHP
use Maize\Encryptable\Encryption; $encrypted = "your-encrypted-value"; $value = Encryption::php()->decrypt($value); // returns the decrypted value
Manually decrypt via DB
use Maize\Encryptable\Encryption; $encrypted = "your-encrypted-value"; $encryptedQuery = Encryption::db()->encrypt($value); // returns the query used to find the decrypted value
Custom validation rules
You can use one of the two custom rules to check the uniqueness or existence of a given encryptable value.
ExistsEncrypted is an extension of Laravel's Exists rule, whereas UniqueEncrypted is an extension of Laravel's Unique rule.
You can use them in the same way as Laravel's base rules:
use Maize\Encryptable\Rules\ExistsEncrypted; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; $data = [ 'email' => 'email@example.com', ]; Validator::make($data, [ 'email' => [ 'required', 'string', 'email', new ExistsEncrypted('users'), // checks whether the given email exists in the database Rule::existsEncrypted('users') // alternative way to invoke the rule ], ]);
use Maize\Encryptable\Rules\UniqueEncrypted; use Illuminate\Support\Facades\Validator; $data = [ 'email' => 'email@example.com', ]; Validator::make($data, [ 'email' => [ 'required', 'string', 'email', new UniqueEncrypted('users'), // checks whether the given email does not already exist in the database Rule::uniqueEncrypted('users') // alternative way to invoke the rule ], ]);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
gestazion/laravel-encryptable 适用场景与选型建议
gestazion/laravel-encryptable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 121 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「encrypt」 「encryptable」 「anonymize」 「maize-tech」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gestazion/laravel-encryptable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gestazion/laravel-encryptable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gestazion/laravel-encryptable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine2 behavioral extensions which allows to transform (encrypt, decrypt, hash) your data automatically
Laravel Encryptable
Encrypted symfony entity's by verified and standardized libraries
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
♺ Laravel Nova Hashids card. Convert your ids.
A library for reading KeePass 2.x databases
统计信息
- 总下载量: 121
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-30