felixsand/phpsst
Composer 安装命令:
composer require felixsand/phpsst
包简介
A PHP library for distributing (one time) passwords/secrets in a more secure way
README 文档
README
A PHP library for distributing (one time) passwords/secrets in a more secure way
Installation
Add the package as a requirement to your composer.json:
$ composer require felixsand/phpsst
Usage
<?php use PhPsst\PhPsst; use PhPsst\Storage\FileStorage; $phPsst = new PhPsst(new FileStorage('data/passwords', 10)); $secret = $phPsst->store('my secret password'); echo "Retrieve the password from: https://example.net/get-password?secret={$secret}";
<?php use PhPsst\PhPsst; use PhPsst\Storage\FileStorage; $phPsst = new PhPsst(new FileStorage('data/passwords', 10)); $decryptedPassword = $phPsst->retrieve($_GET['secret']); echo "The password stored: {$decryptedPassword}";
Storage Classes
FileStorage
The most basic of the storage classes is the FileStorage. It's also (generally) the most insecure and if you store a lot of passwords there's a performance issue due to the garbage collector being very crude. It is however the easiest way to try out the library and useful during development. The constructor parameter $gcProbability is a value from 0 and up, where 0 disables the GC; 1 means it's run for every file write; 10 means it got a 10% probability of running; etc. It's not recommended to turn it off.
$phPsst = new PhPsst(new FileStorage('data/passwords', 10));
RedisStorage
The recommended production storage class is the RedisStorage. It has great performance even during heavy use and since it removes the passwords with expired TTL automatically, it's more secure than the other options. It's important to note that if you're not reviewing the Redis configuration, it might purge entries even before the item's TTL has expired (if it's memory limit is reached) and the items will only live for as long as the server is running. This might be desired properties in certain cases, but you need to be aware of it when setting up the solution.
$redis = new \Predis\Client(array( 'host' => '10.0.0.1', 'port' => 6380, )); $phPsst = new PhPsst(new RedisStorage($redis));
SqLiteStorage
If you don't have access to Redis, another storage engine that is suitable for production use is the SqLiteStorage. It's not as secure as the RedisStorage, mainly because of it's dependency on a garbage collector; as well as the possibility that the SqLite DB file might be included in backups, etc. It's also not suitable for setups with several webservers without access to a shared filesystem. The constructor parameter $gcProbability is the same as for the FileStorage.
$db = new \SQLite3('path/to/sqlite.db'); $phPsst = new PhPsst(new SqLiteStorage($db, 10));
Requirements
- PHP 8.1 or above.
- Redis (for the Redis Storage)
Demo
- Docker
docker run -p 80:80 felixsand/phpsst - See: github.com/felixsand/phpsst-demo
Author
Felix Sandström http://github.com/felixsand
Special thanks
- Andreas http://github.com/jandreasn for peer review
- Chris Wolf https://github.com/crslp for bumping the library to PHP 8.1
License
Licensed under the MIT License - see the LICENSE file for details.
felixsand/phpsst 适用场景与选型建议
felixsand/phpsst 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「distribution」 「password」 「secret」 「safely」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 felixsand/phpsst 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 felixsand/phpsst 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 felixsand/phpsst 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Base bundle for Symfony Distributions
A PHP library to encrypt/decrypt secrets using OpenSSL.
A Symfony bundle to handle secrets.
The PHP class PasswordGenerator serves as a password generator to create memorable passwords like the keychain of macOS ≤ 10.14 did.
Manage secrets when deploying Laravel to Google App Engine (Standard or Flexible). Store all secrets in Google Datastore
Anyrel - Distributor
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-06