petrknap/data-signer
Composer 安装命令:
composer require petrknap/data-signer
包简介
Data Signer
关键字:
README 文档
README
This library provides a logic for digital signing and validating of a binary data.
Inputs and outputs are binary data, don't be afraid to use the petrknap/binary.
Implementations
- Edwards-curve Digital Signature Algorithm (Ed25519)
- Hash-based Message Authentication Code (HMAC)
- Sodium (Ed25519)
Usage
The basic use of a Data Signer interface is quite simple:
use PetrKnap\DataSigner\Some; $signer = new Some\DataSigner(); $data = 'some data'; $signature = $signer->sign($data); if ($signer->verify($data, $signature)) { echo 'Data was successfully verified by signature.'; }
Domain-specific signing
If you need to limit the validity of the signature to a specific purpose (domain), just set it to the Data Signer service:
use PetrKnap\DataSigner\Some; $signer = new Some\DataSigner(); $data = 'some data'; $signature = $signer->withDomain('password_reset')->sign($data); if (!$signer->withDomain('cookies')->verify($data, $signature)) { echo 'You can not use signature generated for `password_reset` in `cookies`.'; }
Time-limited signing
If you need to limit the validity of the signature to specific time (expiration), just give it to the Data Signer's method sign:
use PetrKnap\DataSigner\Some; $signer = new Some\DataSigner(); $data = 'some data'; $signature = $signer->sign($data, expiresAt: new DateTimeImmutable('2025-04-05 09:40:53+02:00')); if (!$signer->verify($data, $signature)) { echo 'You can not use signature after its expiration.'; }
Signable data transfer object
If you communicate through data transfer objects, you can use a Signable Data interface:
use PetrKnap\DataSigner\Some; $apiClient = new class (new Some\DataSigner()) { public function __construct(private readonly Some\DataSigner $dataSigner) {} public function put(Some\DataTransferObject $payload): void { $request = [ 'payload' => $payload, 'signature' => (string) $this->dataSigner->sign($payload)->encode()->base64(), ]; echo json_encode($request); # here should be the API call } }; $apiClient->put(new Some\DataTransferObject( property: 'some value', ));
Communication trough 3rd party machine
If you need to sign data forwarded trough 3rd party machine (f.e. by token or cookie), you can use the Signature with data:
use PetrKnap\Binary\Binary; use PetrKnap\DataSigner\Some; $signer = new Some\DataSigner(); $passwordResetToken = (string) $signer->withDomain('password_reset')->sign( data: 'some_user', expiresAt: (new DateTimeImmutable())->modify('+3 hours'), )->encode(withData: true)->zlib()->base64(urlSafe: true); $verifiedUserIdentifier = $signer->withDomain('password_reset')->verified( (string) Binary::decode($passwordResetToken)->base64()->zlib(), )->orElseThrow(); echo "Verified user identifier is `{$verifiedUserIdentifier}`.";
WARNING: The data are only signed (readable), use the petrknap/crypto-sodium if you need to encrypt them.
Run composer require petrknap/data-signer to install it.
You can support this project via donation.
The project is licensed under the terms of the LGPL-3.0-or-later.
petrknap/data-signer 适用场景与选型建议
petrknap/data-signer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 91 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「cryptography」 「signature」 「signing」 「hmac」 「Curve25519」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 petrknap/data-signer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 petrknap/data-signer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 petrknap/data-signer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DUKPT implementation in PHP
Provide a way to secure accesses to all routes of an symfony application.
接口签名验证
A library for reading KeePass 2.x databases
It's a barebone security class written on PHP
Laravel authentication middleware for UZI passes.
统计信息
- 总下载量: 91
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2025-04-06