petrknap/data-signer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 petrknap/data-signer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 91
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2025-04-06