joelwmale/laravel-encryption
最新稳定版本:2.1.4
Composer 安装命令:
composer require joelwmale/laravel-encryption
包简介
A package to easily encrypt & decrypt model fields in Laravel using OpenSSL.
README 文档
README
A package to easily encrypt & decrypt model fields in Laravel using OpenSSL.
Key Features
- Encrypt and decrypt module attributes easily
- Minimal configuration
- Comes with a selection of eloquent builders for easy queries
- Growing support for casting encryptable data
Installation
You can install the package via composer:
composer require canaryau/laravel-encryption
Usage
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Joelwmale\LaravelEncryption\Traits\EncryptsAttributes; class User extends Model { use EncryptsAttributes; protected $encryptableAttributes = [ 'first_name', 'last_name', 'date_of_birth', 'email_verified_at', ]; protected $encryptableCasts = [ 'date_of_birth' => 'date', 'email_verified_at' => 'datetime' ]; }
Configuration
Publshing The Configuration
The configuration file looks like this:
return [ /** * Enable or disable the encryption. */ 'enabled' => env('LARAVEL_ENCRYPTION_ENABLED', true), /** * The encryption key. * * Default: your app key. */ 'key' => env('LARAVEL_ENCRYPTION_KEY', null), /** * The encryption cipher. * * Supports any cipher method supported by openssl_get_cipher_methods(). * * Default: AES-256-CBC. */ 'cipher' => env('LARAVEL_ENCRYPTION_CIPHER', 'AES-256-CBC'), ];
If you need to make any changes to the configuration, feel free to publish the configuration file.
php artisan vendor:publish --provider="Joelwmale\LaravelEncryption\LaravelEncryptionServiceProvider"
Configure Model Attributes To Be Encrypted
This package will only encrypt fields within the $encryptableAttributes array, leaving the rest of the model unencrypted and untouched.
protected $encryptableAttributes = [ 'first_name', 'last_name', ];
This is useful for scenarios where compliance only requires you encrypting specific values and not your entire database.
Casting Encrypted Values
Due to the fact that encrypted values can be quite long, you will need to store them as text fields, meaning you have to give way to native column types.
Also due to the way Laravel handles casting (and the priority it takes) you cannot right now use native casts with encrypted fields.
So we use our own array to determine what fields should be casted to what:
protected $encryptableCasts = [ 'date_of_birth' => 'date', ];
Supported casts
Cast support is still growing, and will be added as time goes on.
- date
- datetime
- json
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
joelwmale/laravel-encryption 适用场景与选型建议
joelwmale/laravel-encryption 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「joelwmale」 「laravel-encryption」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joelwmale/laravel-encryption 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joelwmale/laravel-encryption 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joelwmale/laravel-encryption 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easily add QuillJS with image support to any Laravel Livewire component.
Easily retrieve the ssl certificate for any host
Easily retrieve the ssl certificate for any host
A package to easily encrypt & decrypt model fields in Laravel using OpenSSL.
Provides flexible data encryption adapter for Laravel.
A seamless security layer for Laravel applications that automatically decrypts incoming requests and encrypts outgoing responses to ensure data integrity and confidentiality.
统计信息
- 总下载量: 3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-24