lumensistemas/encryption-laravel
Composer 安装命令:
composer require lumensistemas/encryption-laravel
包简介
Sodium-based encryption, decryption, and blind indexing for Laravel applications.
README 文档
README
Sodium-based encryption, decryption, and blind indexing for Laravel. Provides Eloquent casts for transparent field-level encryption with optional authorization hooks (e.g. LGPD/GDPR compliance).
Installation
composer require lumensistemas/encryption-laravel
Publish the configuration file:
php artisan vendor:publish --tag=encryption-laravel-config
Generate key files:
php artisan encryption:generate-keys
This creates storage/encryption.key and storage/authentication.key with 0600 permissions.
You can specify a custom directory:
php artisan encryption:generate-keys --path=/etc/secrets
Use --force to overwrite existing key files.
Add the key file paths to .env:
ENCRYPT_ENC_KEY_PATH=/path/to/your/app/storage/encryption.key ENCRYPT_AUTH_KEY_PATH=/path/to/your/app/storage/authentication.key
Security: Keys are read from files rather than environment variables. This prevents accidental exposure through
phpinfo(), debug pages, logs, or process listings. Key files should have restrictive permissions (600) and be excluded from version control.
Usage
Facade
use LumenSistemas\Encrypt\Facades\Encryption; use LumenSistemas\Encrypt\ValueObjects\SecretString; // Encrypt & decrypt $ciphertext = Encryption::encrypt(new SecretString('secret')); $plaintext = Encryption::decrypt($ciphertext)->get(); // 'secret' // Hash & verify (blind index) $hash = Encryption::hash(new SecretString('secret')); Encryption::verify(new SecretString('secret'), $hash); // true
Eloquent Casts
AsEncryptedString
Encrypts on write, decrypts on read:
use LumenSistemas\Encrypt\Casts\AsEncryptedString; class User extends Model { protected $casts = [ 'cpf' => AsEncryptedString::class, ]; }
AsBlindIndex
Stores a deterministic hash for searching encrypted columns:
use LumenSistemas\Encrypt\Casts\AsBlindIndex; use LumenSistemas\Encrypt\Casts\AsEncryptedString; class User extends Model { protected $casts = [ 'email_encrypted' => AsEncryptedString::class, 'email_index' => AsBlindIndex::class, ]; } // Query by blind index use LumenSistemas\Encrypt\Facades\Encryption; use LumenSistemas\Encrypt\ValueObjects\SecretString; $user = User::where('email_index', Encryption::hash(new SecretString($email)))->first();
Authorization & Audit Hook
Register a callback to authorize and/or log access before decryption. This is useful for LGPD/GDPR compliance:
use LumenSistemas\Encrypt\Casts\AsEncryptedString; // In a ServiceProvider boot(): AsEncryptedString::authorizeUsing(function (Model $model, string $key) { // Log every access AuditLog::record(auth()->user(), $model, $key); // Deny or mask if (! auth()->user()->can('view-sensitive', $model)) { return '***.***.***-**'; // return masked value instead of decrypting } return true; // allow decryption });
The callback receives (Model $model, string $key, array $attributes) and should:
- Return
trueto allow decryption - Return a
stringto return a masked value (skips decryption entirely) - Throw an exception to deny access
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
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.
lumensistemas/encryption-laravel 适用场景与选型建议
lumensistemas/encryption-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 335 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「encryption」 「laravel」 「sodium」 「lumensistemas」 「encryption-laravel」 「blind-indexing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lumensistemas/encryption-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lumensistemas/encryption-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lumensistemas/encryption-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple helpers for encrypt and decrypt content
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
Allows installation of Laravel where the PHP Mcrypt extension is not available. Provides encryption using OpenSSL, or by disabling encryption entierly.
High-level cryptographic primitives and security utilities for Maatify systems including password hashing, reversible encryption, HKDF key derivation, and key rotation.
统计信息
- 总下载量: 335
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 34
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-26