PHPackages                             lswl/sign - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lswl/sign

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lswl/sign
=========

Signature generation.

v1.0.0(4y ago)0401MITPHPPHP ^7.3|^8.0

Since Oct 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/linshaowl/sign)[ Packagist](https://packagist.org/packages/lswl/sign)[ Docs](https://linshaowl.com/)[ RSS](/packages/lswl-sign/feed)WikiDiscussions 1.0 Synced 5d ago

READMEChangelogDependenciesVersions (3)Used By (1)

介绍
--

[](#介绍)

> 使用多种方式生成计算签名，并记录签名步骤。

安装
--

[](#安装)

使用以下命令安装：

```
composer require lswl/sign

```

使用
--

[](#使用)

### 简易使用方式：

[](#简易使用方式)

```
use Lswl\Signature\HttpBuildQuery;
use Lswl\Signature\Json;

// 数据
$data = [
    'key' => 'value',
];
// 密钥
$key = 'key';

// 使用 http_build_query 方式签名
$sign = (new HttpBuildQuery($data, $key))->sign();

// 使用 json 方式签名
$sign = (new Json($data, $key))->sign();
```

### 完整使用方式：

[](#完整使用方式)

```
use Lswl\Signature\HttpBuildQuery;
use Lswl\Signature\Algorithms\Hash;

// 签名实例
$sign = new HttpBuildQuery();

// 算法(默认md5)
$algorithm = new Hash();
// 使用 sha256 算法
$algorithm->setAlgorithm('sha256');

// 设置签名数据、密钥、算法
$sign->setData(['key' => 'value'])
    ->setKey('key')
    ->setAlgorithm($algorithm);

// 签名结果字符串
$signStr = $sign->sign();

// 签名步骤数据
$stepArr = $sign->getStep();
// 签名步骤数据字符串
$stepStr = $sign->getStepAsString();
```

扩展
--

[](#扩展)

### 添加新的签名方式

[](#添加新的签名方式)

> 继承 `\Lswl\Signature\AbstractSignature` 并实现方法 `buildSignStr`

```
use Lswl\Signature\AbstractSignature;

class Serialize extends AbstractSignature
{
    /**
     * @inheritDoc
     */
    protected function buildSignStr(array $data): string
    {
        return serialize($data);
    }
}

// 数据
$data = [
    'key' => 'value',
];
// 密钥
$key = 'key';
// 使用 serialize 方式签名
$sign = (new Serialize($data, $key))->sign();
```

### 添加新的算法

[](#添加新的算法)

> 继承 `\Lswl\Signature\Algorithms\AbstractAlgorithm` 并实现方法 `run`

```
use Lswl\Signature\Algorithms\AbstractAlgorithm;
use Lswl\Signature\Json;

class Md5 extends AbstractAlgorithm
{
    /**
     * @inheritDoc
     */
    public function run(string $str): string
    {
        return md5($str);
    }
}

// 数据
$data = [
    'key' => 'value',
];
// 密钥
$key = 'key';
// 使用 json 方式签名, 并设置 Md5 算法
$sign = (new Json($data, $key))
    ->setAlgorithm(new Md5())
    ->sign();
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1676d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/406878610be7a05aa8767eb4c0c6158b60e085f191d7d6a201f122bb9ff71043?d=identicon)[lswl](/maintainers/lswl)

---

Top Contributors

[![linshaowl](https://avatars.githubusercontent.com/u/19506950?v=4)](https://github.com/linshaowl "linshaowl (1 commits)")

---

Tags

signaturesignlswl

### Embed Badge

![Health badge](/badges/lswl-sign/health.svg)

```
[![Health](https://phpackages.com/badges/lswl-sign/health.svg)](https://phpackages.com/packages/lswl-sign)
```

###  Alternatives

[brinley/jsignature

Signature For Javascript

69930.4k1](/packages/brinley-jsignature)[spomky-labs/pki-framework

A PHP framework for managing Public Key Infrastructures. It comprises X.509 public key certificates, attribute certificates, certification requests and certification path validation.

2725.9M11](/packages/spomky-labs-pki-framework)[sop/crypto-types

A PHP library of various ASN.1 types for cryptographic applications.

111.4M33](/packages/sop-crypto-types)[falseclock/advanced-cms

A PHP Library that allows you to decode and manipulate CAdES or in other words CMS Advanced Electronic Signatures described in ETSI standart TS 101 733.

223.2k](/packages/falseclock-advanced-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
