PHPackages                             xiuchuan/ecc - 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. xiuchuan/ecc

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

xiuchuan/ecc
============

php sm2 sm3 sm4 国密算法整理

1.0.1(4y ago)22332MITPHPPHP ^7.0

Since Nov 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/tanikawa-dev/ecc)[ Packagist](https://packagist.org/packages/xiuchuan/ecc)[ RSS](/packages/xiuchuan-ecc/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (3)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

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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 ~6 days

Total

2

Last Release

1641d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5105c745ff2a5fe17735c3db6f9130ab26e3287bf33034b348ae46a7284b7418?d=identicon)[tanikawa-dev](/maintainers/tanikawa-dev)

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

PHPackages © 2026

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