PHPackages                             unntech/encrypt - 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. unntech/encrypt

ActiveLibrary

unntech/encrypt
===============

Commonly used encryption libraries

v1.0.7(6mo ago)1322MITPHPPHP &gt;=7.4

Since May 28Pushed 6mo agoCompare

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

READMEChangelog (7)DependenciesVersions (8)Used By (2)

Encrypt 1.0
===========

[](#encrypt-10)

[![Latest Stable Version](https://camo.githubusercontent.com/21bd838b20d08357b6bd0e70ba208d63f118310d58cbb94364d46237b7bf13a5/68747470733a2f2f706f7365722e707567782e6f72672f756e6e746563682f656e63727970742f762f737461626c65)](https://packagist.org/packages/unntech/encrypt)[![Total Downloads](https://camo.githubusercontent.com/f690102dd31a3112f5357b8ac5913b81adee5bef82121f1a8258baba4bd00b9b/68747470733a2f2f706f7365722e707567782e6f72672f756e6e746563682f656e63727970742f646f776e6c6f616473)](https://packagist.org/packages/unntech/encrypt)[![Latest Unstable Version](https://camo.githubusercontent.com/7acf0868ca3f9d0268e86cad7796e5c082f198e9a3ae362a6863598677ea9727/687474703a2f2f706f7365722e707567782e6f72672f756e6e746563682f656e63727970742f762f756e737461626c65)](https://packagist.org/packages/unntech/encrypt)[![PHP Version Require](https://camo.githubusercontent.com/f31c31caea3e145a8db3f9fda89c531fc5b80b82e05130be9938df07fcdf7f36/687474703a2f2f706f7365722e707567782e6f72672f756e6e746563682f656e63727970742f726571756972652f706870)](https://packagist.org/packages/unntech/encrypt)[![License](https://camo.githubusercontent.com/5fb295e4c63ae753eb9911112d7bb110ca4ef4b12aee1dea4fb35f7de23577bd/68747470733a2f2f706f7365722e707567782e6f72672f756e6e746563682f656e63727970742f6c6963656e7365)](https://packagist.org/packages/unntech/encrypt)

常用的加密库，封装开箱即用

主要新特性
-----

[](#主要新特性)

- 采用`PHP7`强类型（严格模式）

> Encrypt 1.0 的运行环境要求PHP7.4+，兼容PHP8

安装
--

[](#安装)

```
composer require unntech/encrypt

```

更新框架使用

```
composer update unntech/encrypt

```

目录结构

```
encrypt/
├── src                                     #
│   ├── AES.php                             # AES（Advanced Encryption Standard，高级加密标准）
│   ├── ECDSA.php                           # ECDSA 椭圆曲线数字签名
│   ├── Encode.php                          # 编码常用函数
│   ├── encrypt.md                          # 加解密及验签文档
│   ├── Request.php                         # Api 请求类
│   ├── Response.php                        # Api 输出类
│   └── RSA.php                             # RSA 加密库
├── tests                                   # 测试样例，可删除
├── composer.json                           #
├── license.txt
└── README.md

```

加解密及验签文档
--------

[](#加解密及验签文档)

[encrypt.md](src/encrypt.md)

使用示例
----

[](#使用示例)

### access\_token 生成及校验

[](#access_token-生成及校验)

```
use UNNTech\Encrypt\WebToken;

// 生成 token
$token = WebToken::instance('aes key')->getToken(['sub'=>123], 600);
// 校验token及获取数据
$data = WebToken::instance()->verifyToken($token);
```

### AES 加解密

[](#aes-加解密)

```
use UNNTech\Encrypt\AES;

$aes = new AES('key');
// 加密
$ciphertext = $aes->encrypt('plaintext');
// 解密
$plaintext = $aes->decrypt($ciphertext);
```

### ECDSA 验签及加解密

[](#ecdsa-验签及加解密)

```
use UNNTech\Encrypt\ECDSA;

$ecdsa = new ECDSA();
//生成ECDSA公私钥
$c = $ecdsa->createKey();
var_dump($c);

$publicKey = $c['public'];
$privateKey = $c['private'];

$ecdsa = new ECDSA( $publicKey, $privateKey );
$data = '测试ECDSA数据';
//生成ECDSA签名
$sign = $ecdsa->sign( $data );
//验证ECDSA签名
$y = $ecdsa->verifySign( $data, $sign );
var_dump( $sign, $y );

$arr = ['order'=>'20200826001','money'=>200];
//生成ECDSA签名数据数组
$arr = $ecdsa->signArray($arr);
//验证ECDSA签名数组
$y = $ecdsa->verifySignArray($arr);
var_dump($arr,$y);

//ECIES加密
$x = $ecdsa->encrypt( $data );
var_dump( $x );
//ECIES解密
$y = $ecdsa->decrypt( $x['ciphertext'], $x['tempPublicKey'], $x['iv'], $x['mac'], $x['code'] );
var_dump( $y );
```

### RSA 验签及加解密

[](#rsa-验签及加解密)

```
use UNNTech\Encrypt\RSA;

//生成RSA公私钥
$rsa = new RSA();
$c = $rsa->createKey();
var_dump($c);

$publicKey = $c['public'];
$privateKey = $c['private'];

$rsa = new RSA( $publicKey, $privateKey );
$data = '测试RSA2';
//生成RSA签名
$sign = $rsa->sign( $data );
//验证RSA签名
$y = $rsa->verifySign( $data, $sign );
var_dump( $sign, $y );

$arr = ['order'=>'20200826001','money'=>200];
//生成RSA签名数据数组
$arr = $rsa->signArray($arr);
//验证RSA签名数组
$y = $rsa->verifySignArray($arr);
var_dump($arr,$y);
//RSA加密
$x = $rsa->encrypt( $data );
//RSA解密
$y = $rsa->decrypt( $x );
var_dump( $x, $y );
```

### Request 请求数据生成及验签

[](#request-请求数据生成及验签)

```
use UNNTech\Encrypt\Request;

$data = [
    'order_id' => 123,
    'money'    => 1001.23,
];

$req = Request::instance(['secret'=>'secret_key', 'signType'=>'SHA256'])::headers(['app'=>'IOS', 'access_token'=>'token'])::generate($data, 'array');
var_dump($req);
$request = json_encode($req);
dv($request);

$c = Request::verifySign($req);
if($c){
    echo "Verify Sign Success. \n";
}else{
    echo "Verify Sign Fail. \n";
}
```

### Response 数据格式化输出

[](#response-数据格式化输出)

```
use UNNTech\Encrypt\Response;

$data = ['abc'=>123];
Response::instance(['secret' => 'secret_key', 'signType'=>'SHA256'])::success($data);

// 验证请求的数据是否合法
Response::instance(['secret' => 'secret_key'])::verifySign($request)
```

命名规范
----

[](#命名规范)

`Encrypt` 遵循PSR命名规范和PSR-4自动加载规范。

参与开发
----

[](#参与开发)

直接提交PR或者Issue即可

> [版本更新记录 CHANGELOG](CHANGELOG.md)

版权信息
----

[](#版权信息)

Encrypt 遵循 MIT 开源协议发布，并提供免费使用。

本项目包含的第三方源码和二进制文件之版权信息另行标注。

版权所有Copyright © 2025 by Jason Lin All rights reserved。

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance68

Regular maintenance activity

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

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

Recently: every ~37 days

Total

7

Last Release

190d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/41ed0737519313bb52a1c118a720dd65f4c238a2a805825eeef7bf2b41e05bfa?d=identicon)[unntech](/maintainers/unntech)

---

Top Contributors

[![unntech](https://avatars.githubusercontent.com/u/98684048?v=4)](https://github.com/unntech "unntech (13 commits)")

### Embed Badge

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

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

PHPackages © 2026

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