diontech/laravel-vault
Composer 安装命令:
composer require diontech/laravel-vault
包简介
Building vaults and decrypted/encryped secrets. Using specfic keys per vault (or per secret if you want to) is implemented. Vaults can be a standalone or related to your app`s models.
README 文档
README
about Vault
With Vault, you can create vaults as application standalones or related to a model in your app, for example every user can have personal vaults. Each vault can contain secrets. Instead of using the default decrypt/encrypt functions, Vault will protect secrets using the keys you will choose. For example, an user can define its 'magic secret password' and must provide it every time he wants to have access to a secret. The way you will handle this is dependant to your case.
Vault will handle the key length internally and make sure, the length is 16 or 32, dependant to the cipher you will use (AES-128-CBC = 16, AES-256-CBC = 32). So you can choose the secret key you will want to.
releases / laravel support
- laravel 8: v1.1.x
- laravel 9: v1.2.x
installation
composer require diontech/laravel-vault
php artisan migrate
usage
//creating a vault without a related model $vault = \DionTech\Vault\Models\Vault::create([ 'name' => 'application vault' ]); //use default APP_KEY, adding secret \DionTech\Vault\Support\Facades\Vault::open($vault)->add("facaded_secret", "AN_API_KEY"); //use default APP_KEY, overwrite secret \DionTech\Vault\Support\Facades\Vault::open($vault)->overwrite("facaded_secret", "AN_API_KEY_overwritten"); //use default APP_KEY, get secret \DionTech\Vault\Support\Facades\Vault::open($vault)->get("facaded_secret"); //use own key, adding secret \DionTech\Vault\Support\Facades\Vault::open($vault)->useKey("DO_NOT_FORGETT_IT")->add("facaded_secret", "AN_API_KEY"); //use own key, overwrite secret \DionTech\Vault\Support\Facades\Vault::open($vault)->useKey("DO_NOT_FORGETT_IT")->overwrite("facaded_secret", "AN_API_KEY_overwritten"); //use own key, get secret \DionTech\Vault\Support\Facades\Vault::open($vault)->useKey("DO_NOT_FORGETT_IT")->get("facaded_secret");
//adding a vault using the polymorphic relation //at your model, add morphMany relation, for example at User: use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { //... public function vaults() { return $this->morphMany(\DionTech\Vault\Models\Vault::class, 'vaultable'); } } //now add a vault at an $user instance later $user = User::first(); $user->vaults()->create([ 'name' => 'personal' ]); //now you will have access to the methods like using a facade when you will use the related model based vaults(), starting with open() $user->vaults()->first()->add("AN_API_KEY", "this-is-the-sensible-value"); $user->vaults()->first()->overwrite("AN_API_KEY", "this-is-the-sensible-value-overwritten"); $user->vaults()->first()->get("AN_API_KEY");
There are now a few new options more now of how to write the code:
Vault::open("a vault name")->add("facaded_secret", "simple value"); //will create the vault
or when want a relational based vault:
$user = User::first(); Vault::setContext($user)->open("personal")->add('bad_password_storing_itself', '12345678'); //will create a vault in relation to the user
So vaults are created or loaded (when already exists) when you only type a string.
changing the KeyService hash alogorithm
You can publish the config file - after that, you can change the algo at config/vault.php; default is set to sha512. Supported are listed at https://www.php.net/manual/de/function.hash-hmac-algos.php.
diontech/laravel-vault 适用场景与选型建议
diontech/laravel-vault 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 899 次下载、GitHub Stars 达 11, 最近一次更新时间为 2021 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 diontech/laravel-vault 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 diontech/laravel-vault 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 899
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-05