PHPackages                             seffeng/cryptlib - 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. seffeng/cryptlib

ActiveLibrary[Security](/categories/security)

seffeng/cryptlib
================

PHP extension cryptlib

v0.1.4(1y ago)110.3k↓48.5%4MITPHPPHP &gt;=7.1.3

Since Jun 1Pushed 1y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (6)Used By (4)

cryptlib
--------

[](#cryptlib)

### 安装

[](#安装)

```
# 安装
$ composer require seffeng/cryptlib
```

### 目录说明

[](#目录说明)

```
├─src
│  │  Crypt.php
│  │  openssl.cnf
│  ├─Clients
│  │    RSA.php
│  │    SM3.php
│  │    SM4.php
│  ├─Exceptions
│  │    CryptException.php
│  └─Interfaces
│       CryptInterface.php
└─tests
    CryptTest.php

```

### 方法

[](#方法)

```
$crypt = new Crypt();
# 1、生成 KEY，保存秘钥对
$keys = $crypt->createKey();
```

```
# 1、加密
$crypt->loadKey($publicKey);
$crypt->encrypt($plaintext);

# 2、解密
$crypt->loadKey($privateKey);
$crypt->decrypt($entext);

# 3、签名
$crypt->loadKey($privateKey);
$crypt->sign($message);

# 4、签名验证
$crypt->loadKey($publicKey);
$crypt->verify($message, $sign);

# 5、SM3
$crypt = new Crypt('SM3');
$crypt->encrypt('abcd');

# 6、SM4
$crypt = new Crypt('SM4');
$iv = 'EZIwtOeuqf8BI/j3D0CjuQ==';//$crypt->createKey();
$plaintext = '123456';
$entext = $crypt->setIv($iv)->encrypt($plaintext);
$detext = $crypt->setIv($iv)->decrypt($entext);
```

### 示例

[](#示例)

```
/**
 * SiteController
 */
use Seffeng\Cryptlib\Crypt;

class SiteController extends Controller
{
    public function index()
    {
        $crypt = new Crypt();
        // 生成 KEY
        $keys = $crypt->createKey();
        $privateKey = isset($keys['privateKey']) ? $keys['privateKey'] : null;
        $publicKey = isset($keys['publicKey']) ? $keys['publicKey'] : null;
        //$crypt->setPrivateKey($privateKey)->setPublicKey($publicKey);
        $crypt->setEncryptionMode(1);

        $plaintext = '123456';
        // 加密[公钥]
        $entext = $crypt->loadKey($publicKey)->encrypt($plaintext);
        // 解密[私钥]
        $detext = $crypt->loadKey($privateKey)->decrypt($entext);
        var_dump(base64_encode($entext), $detext);

        //$crypt = new Crypt();
        //$keys = $crypt->createKey();
        //$privateKey = isset($keys['privateKey']) ? $keys['privateKey'] : null;
        //$publicKey = isset($keys['publicKey']) ? $keys['publicKey'] : null;

        $plaintext = '654321';
        // 加密[私钥]
        $entext = $crypt->loadKey($privateKey)->encryptByPrivateKey($plaintext);
        // 解密[公钥]
        $detext = $crypt->loadKey($publicKey)->decryptByPublicKey($entext);
        var_dump(base64_encode($entext), $detext);

        //$crypt = new Crypt();
        //$keys = $crypt->createKey();
        //$privateKey = isset($keys['privateKey']) ? $keys['privateKey'] : null;
        //$publicKey = isset($keys['publicKey']) ? $keys['publicKey'] : null;

        $message = 'a=aaa&b=bbb&c=ccc';
        // 签名[私钥]
        $sign = $crypt->loadKey($privateKey)->sign($message);
        // 签名验证[公钥]
        $verify = $crypt->loadKey($publicKey)->verify($message, $sign);

        var_dump(base64_encode($sign), $verify);
    }
}
```

### 备注

[](#备注)

无

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity44

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

Total

5

Last Release

635d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30b3d8cc986a1ad37a55169b11812fea1cae31430dd8dbe1b3436dc58cc885bd?d=identicon)[seffeng](/maintainers/seffeng)

---

Top Contributors

[![seffeng](https://avatars.githubusercontent.com/u/3509779?v=4)](https://github.com/seffeng "seffeng (12 commits)")

---

Tags

phplaravelrsayii2cryptseffeng

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tzsk/otp

A secure, database-free One-Time Password (OTP) generator and verifier for PHP and Laravel.

241641.4k1](/packages/tzsk-otp)[vlucas/pikirasa

PKI public/private RSA key encryption using the OpenSSL extension

104101.1k1](/packages/vlucas-pikirasa)[miladrahimi/phpcrypt

Encryption, decryption, and hashing tools for PHP projects

3171.5k2](/packages/miladrahimi-phpcrypt)

PHPackages © 2026

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