bentools/shh
Composer 安装命令:
composer require bentools/shh
包简介
A PHP library to encrypt/decrypt secrets using OpenSSL.
关键字:
README 文档
README
Shh! 🤫
Shh! is a simple library to deal with secrets. It helps you generate key pairs, encrypt/decrypt a payload, store secrets in a safe way.
For the full background behind this, see the Symfony Bundle documentation
Installation
composer require bentools/shh:^1.0
Usage
Generate keys
use BenTools\Shh\Shh; [$publicKey, $privateKey] = Shh::generateKeyPair();
By default sha512 algorithm is used with a length of 4096 bits.
Example with a passphrase and a different configuration:
use BenTools\Shh\Shh; [$publicKey, $privateKey] = Shh::generateKeyPair('Some passphrase', ['private_key_bits' => 512, 'digest_alg' => 'sha256']);
Change passphrase
You can change the passphrase of an existing key:
use BenTools\Shh\Shh; [$publicKey, $privateKey] = Shh::generateKeyPair(); $privateKey = Shh::changePassphrase($privateKey, null, 'now I have a passphrase');
This generates a new private key.
The public key remains unchanged, and existing secrets can still be decoded, with the new passphrase only.
Encrypt / decrypt secrets
Public key is required to encrypt secrets, while public AND private keys are required to decode them.
use BenTools\Shh\Shh; $shh = new Shh($publicKey, $privateKey); $encoded = $shh->encrypt('foo'); $decoded = $shh->decrypt($encoded);
Payloads are serialized/deserialized using base64.
Secret storage
It allows you to store encrypted secrets. You can safely publish a file containing secrets as soon as the private key is not published.
Only the owners of the private key (and its associated passphrase, if any) will be able to decrypt the secrets in it.
use BenTools\Shh\SecretStorage\JsonFileSecretStorage; use BenTools\Shh\Shh; [$publicKey, $privateKey] = Shh::generateKeyPair('Some passphrase', ['private_key_bits' => 512, 'digest_alg' => 'sha256']); $shh = new Shh($publicKey, $privateKey); $storage = new JsonFileSecretStorage($shh, './secrets.json'); $storage->store('some-secret'); $storage->has('some-secret'); $storage->get('some-secret'); // Reveal $storage->getKeys(); // List known secrets
Tests
./vendor/bin/phpunit
License
MIT
bentools/shh 适用场景与选型建议
bentools/shh 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.97k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2019 年 06 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「encryption」 「passphrase」 「openssl」 「encrypt」 「decryption」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bentools/shh 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bentools/shh 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bentools/shh 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Secure passphrase generator for PHP applications
Diceware Passphrase Generator for Laravel
Password/passphrase strength checking and enforcement
The bundle for easy using json-rpc api on your project
A simple PHP class to encrypt a string and decrypt an encrypted string
A Symfony bundle to handle secrets.
统计信息
- 总下载量: 21.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 10
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-26