PHPackages                             pohoc/crypto-sm - 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. pohoc/crypto-sm

ActiveLibrary[Security](/categories/security)

pohoc/crypto-sm
===============

国密算法 SM2、SM3 和 SM4 的 PHP 版实现

v0.2.3(3w ago)15102MITPHPPHP ^8.0CI passing

Since Mar 6Pushed 3w agoCompare

[ Source](https://github.com/pohoc/crypto-sm)[ Packagist](https://packagist.org/packages/pohoc/crypto-sm)[ Docs](https://github.com/pohoc/crypto-sm)[ RSS](/packages/pohoc-crypto-sm/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (7)Dependencies (7)Versions (10)Used By (2)

Crypto-SM
=========

[](#crypto-sm)

[![PHP Version](https://camo.githubusercontent.com/797997e6cadba3705e20c599aa232ec083afea865ea574892cab7c593e31b140/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532307e253230382e352d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![CI](https://github.com/pohoc/crypto-sm/actions/workflows/php.yml/badge.svg)](https://github.com/pohoc/crypto-sm/actions/workflows/php.yml)

国密算法 SM2、SM3、SM4 的 PHP 实现。

**PHP 国密库** — 支持 SM2 密钥交换、PEM 导入/导出、HMAC-SM3、SM3 流式哈希、SM4 全 6 种模式（ECB/CBC/CFB/OFB/CTR/GCM）和 5 种填充模式。

安装
--

[](#安装)

```
composer require pohoc/crypto-sm
```

环境要求
----

[](#环境要求)

- PHP 8.0 ~ 8.5
- GMP 扩展
- OpenSSL 扩展

### 安装 GMP 扩展

[](#安装-gmp-扩展)

**Ubuntu/Debian:**

```
sudo apt-get install php-gmp
```

**CentOS/RHEL:**

```
sudo yum install php-gmp
```

**macOS (Homebrew):**

```
brew install php@gmp
```

**Windows:**在 php.ini 中启用 php\_gmp.dll 扩展（取消注释）:

```
extension=php_gmp.dll
```

**验证安装:**

```
