PHPackages                             latzou/sm2 - 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. [Security](/categories/security)
4. /
5. latzou/sm2

ActiveLibrary[Security](/categories/security)

latzou/sm2
==========

This is a PHP library for sm2 encrypt decrypt and sm3 hash

2.0.3(1y ago)222.4k—0%4[1 issues](https://github.com/lat751608899/sm2/issues)1MITPHPPHP ^7.0 || ^8.0

Since Jul 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lat751608899/sm2)[ Packagist](https://packagist.org/packages/latzou/sm2)[ RSS](/packages/latzou-sm2/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (7)Used By (1)

### 使用(how to use)

[](#使用how-to-use)

- 可以使用 sm2 加解密， sm3
- composer require latzou/sm2
- php需要安装 gmp 扩展
- 目前只支持未压缩的 sm2 加解密，以 04 开头的
- 加解密数据组合方式为 c1c3c2
- 加解密数据都是 16 进制编码的，其他 Asn.1 格式的数据需自行解析

```
// 针对密钥是 Asn.1 格式的
$data = "";
$key = base64_decode('MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEShQSLl+hSiiJVcUjn6kVmhpCClh0
9RmCEUaKNMOXglHs0BTw1JITOZckfahMn/KHeop+9ubzPEB8fqdehWzzuQ==');
// sm2 加密
$pubKey = new \Lat\Ecc\PublicKey();
$pubKey->parse($key);
$sm2 = new \Lat\Ecc\Sm2();
$res = $sm2->pubEncrypt($pubKey, $data);

$key = base64_decode('MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgmKp8uBbpJhZCXliV
xksD3oM5H1oyDt84MNxiwVN6BAigCgYIKoEcz1UBgi2hRANCAARKFBIuX6FKKIlV
xSOfqRWaGkIKWHT1GYIRRoo0w5eCUezQFPDUkhM5lyR9qEyf8od6in725vM8QHx+
p16FbPO5');
// sm2 解密
$privKey = new \Lat\Ecc\PrivateKey();
$privKey->parse($key);
$a = $sm2->decrypt($privKey, $res);

// 针对密钥是解出来的16进制数据
// sm2 加密
$data = "";
$key = '0451844d8f4e8881806f27169142f7e22932245af841d4b6c705e8e2b3adbb0041616dd0968910e76df6c4f6eb1d6f0ef11188b54bb09f47aa925c15d4ab13c119';
$sm2 = new \Lat\Ecc\Sm2();
$pubKey = new \Lat\Ecc\PublicKey();
$pubKey->parseUncompressedPoint($key);
$res = $sm2->pubEncrypt($pubKey, $data);

// sm2 解密
$privKey = new \Lat\Ecc\PrivateKey();
$privKey->setKey('0f3e3fb2b68197851656e805ddb9825b21b50d5e215894ca5dd5781fe4c4bea8');
$a = $sm2->decrypt($privKey, $res);

```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

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

Total

5

Last Release

631d ago

Major Versions

1.0.1 → 2.0.02022-07-14

PHP version history (2 changes)1.0.1PHP ^5.0

2.0.0PHP ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/cce6b95f9dab5b1655b6a33319ebcda30d2d86b1822fa8902d74dc823bbd806d?d=identicon)[lat751608899](/maintainers/lat751608899)

---

Top Contributors

[![lat751608899](https://avatars.githubusercontent.com/u/19159495?v=4)](https://github.com/lat751608899 "lat751608899 (23 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41478.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

87117.5M63](/packages/bjeavons-zxcvbn-php)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[paragonie/hidden-string

Encapsulate strings in an object to hide them from stack traces

7410.6M39](/packages/paragonie-hidden-string)

PHPackages © 2026

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