PHPackages                             phpsm/phpsm - 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. phpsm/phpsm

ActiveLibrary

phpsm/phpsm
===========

php sm

25PHP

Since Jun 26Pushed 4y agoCompare

[ Source](https://github.com/li781825965/phpsm)[ Packagist](https://packagist.org/packages/phpsm/phpsm)[ RSS](/packages/phpsm-phpsm/feed)WikiDiscussions main Synced 6d ago

READMEChangelogDependenciesVersions (1)Used By (0)

php sm2 sm3 sm4 国密算法整理
======================

[](#php-sm2-sm3-sm4-国密算法整理)

- php版本的国密sm2的签名算法，sm3的hash, sm4的ecb加解密，要求PHP７，打开gmp支持
- 目前如果服务器配套的使用的是openssl 1.1.1x, 目前到1.1.1k ,sm3,sm4都可以直接用openssl\_xxx系列函数直接实现，不必大量的代码,但不支持sm2的签名，sm2的加解密

### SM2

[](#sm2)

- 该算法主体基于PHPECC算法架构，添加了sm2的椭圆参数算法，
- 参考了  童鞋的sm2验签算法，密钥生成算法
- 添加了签名算法， 支持sm2的16进制，base64公私钥的签名，验签算法
- 支持从文件中读取pem文件的签名，验签算法
- sm2的加密解密算法在openssl 1.1.1的版本下自带的函数中暂无sm2的公钥私钥的加密函数，得自己实现，建议使用C，C++的算法，打包成PHP扩展的方式
- 由于 openssl没有实现sm2withsm3算法，用系统函数无法实现签名及证书的自签名分发

### SM3

[](#sm3)

- 该算法直接使用  童鞋的sm3, 未做修改
- 也可使用 openssl的函数, 详见openssl\_tsm3.php

### SM4

[](#sm4)

- 该算法直接使用  童鞋的sm4算法
- 只实现了ecb算法，没有实现cbc算法
- 在openssl 1.1.1下可使用系统的函数，已支持sm4-cbc,sm4-cfb,sm4-ctr,sm4-ecb,sm4-ofb， 详见openssl\_tsm4.php

### 总结

[](#总结)

- 这里封装的测试函数已与相关的js, python, java都可以互签互认
- js:
- python:
- java:
- openssl: 升到1.1.1以后，支持sm3,sm4的加解密，还不支持sm2的公私钥加解密，也不支持sm2的签名，得使用原生代码实现，签名中需要实现sm2withsm3, openssl1.1.1只实现了sm2whithsha256

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.2% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4add6e5493cf15bfe1834649535690d65e78fd5126bdd72f85ec027fa2dffc60?d=identicon)[li781825965](/maintainers/li781825965)

---

Top Contributors

[![lpilp](https://avatars.githubusercontent.com/u/36149355?v=4)](https://github.com/lpilp "lpilp (15 commits)")[![li781825965](https://avatars.githubusercontent.com/u/18167608?v=4)](https://github.com/li781825965 "li781825965 (2 commits)")

### Embed Badge

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

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

PHPackages © 2026

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