PHPackages                             topphp/topphp-rsa - 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. topphp/topphp-rsa

ActiveLibrary[Security](/categories/security)

topphp/topphp-rsa
=================

RSA 非对称加密解密

v1.0.1(6y ago)120MITPHPPHP ~7.2CI failing

Since May 14Pushed 6y ago1 watchersCompare

[ Source](https://github.com/topphp/topphp-rsa)[ Packagist](https://packagist.org/packages/topphp/topphp-rsa)[ RSS](/packages/topphp-topphp-rsa/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

topphp-rsa
==========

[](#topphp-rsa)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae0f52c74a61961e9db29f01772b38ba685e4a7834a3d52453f28b289d9029e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f707068702f636f6d706f6e656e742d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/topphp/component-builder)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/005f716166c16d1e3c68f324454da4b8e9beb429be5097bd10b75455fb02117d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f707068702f636f6d706f6e656e742d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/topphp/component-builder)

> 这是一个RSA的非对称加密解密组件

包含方法
----

[](#包含方法)

- 创建公私钥文件
- 创建CA证书文件
- 公钥加密---私钥解密
- 私钥加密---公钥解密
- 签名---验签
- CA证书公钥加密---私钥解密

组件结构
----

[](#组件结构)

```
src/
tests/
vendor/

```

安装
--

[](#安装)

```
    composer require topphp/topphp-rsa
```

用法
--

[](#用法)

```
    命名空间引用：use Topphp\TopphpRsa\RSA2;
    $rsaObj = new RSA2();
    $data = "要加密的数据";
    $eData = $rsaObj->cryptCode($data, "E");// E 加密
    $dData = $rsaObj->cryptCode($eData, "D");// D 解密

    组件还包含如下方法：
        createSecretKey() // 创建公私钥文件
        createCertificate() // 创建CA证书文件
        cryptReCode() // 私钥加密---公钥解密
        getSign() // 私钥生成签名
        checkSign() // 公钥验签
        certEncrypt() // CA证书公钥加密
        certDecrypt() // CA证书私钥解密

    助手类（只需要部署时调用一次 RsaHelper::generateSecretKey() 方法，以后加密解密会自动获取公私钥文件内容）
        RsaHelper::handler($publicKeyFile, $privateKeyFile);// 返回原始RSA2对象句柄
        RsaHelper::generateSecretKey($option);// 生成公私钥文件
        RsaHelper::generateCertificate($option);// 生成CA证书文件（有使用CA证书加密解密的需求时，调用此方法生成证书）
        RsaHelper::foPubEncrypt($data);// 【公钥加密---私钥解密】 之 加密 支持数组（常用于加密解密）
        RsaHelper::foPriDecrypt($pubEncStr);// 【公钥加密---私钥解密】 之 解密（常用于加密解密）
        RsaHelper::rePriEncrypt($data);// 【私钥加密---公钥解密】 之 加密 支持数组（常用于签名验签）
        RsaHelper::rePubDecrypt($priEncStr);// 【私钥加密---公钥解密】 之 解密（常用于签名验签）
        RsaHelper::generateSignature($data);// 生成签名 支持数组
        RsaHelper::verifySignature($signStr, $data);// 验证签名
        RsaHelper::certEncrypt($data);// 【CA证书公钥加密---私钥解密】 之 加密 支持数组
        RsaHelper::certDecrypt($certEncStr, $priPass);// 【CA证书公钥加密---私钥解密】 之 解密
        RsaHelper::getErrorMsg();// 获取内部错误信息

    更多详细使用方式参看单元测试文件
```

修改日志
----

[](#修改日志)

有关最近更改的内容的详细信息，请参阅更改日志（[CHANGELOG](CHANGELOG.md)）。

测试
--

[](#测试)

```
    ./vendor/bin/phpunit tests/RSA2Test.php
```

贡献
--

[](#贡献)

详情请参阅贡献（[CONTRIBUTING](CONTRIBUTING.md)）和行为准则（[CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md)）。

安全
--

[](#安全)

如果您发现任何与安全相关的问题，请发送电子邮件至，而不要使用问题跟踪器。

信用
--

[](#信用)

- [topphp](https://github.com/topphp)
- [All Contributors](../../contributors)

许可证
---

[](#许可证)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 57.9% 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 ~0 days

Total

2

Last Release

2240d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3774ddafd6cc1dbff3db41386611fac2236c095e12c9e99f1717da35ad792087?d=identicon)[topphp](/maintainers/topphp)

---

Top Contributors

[![344147805](https://avatars.githubusercontent.com/u/26813709?v=4)](https://github.com/344147805 "344147805 (11 commits)")[![go-sleep](https://avatars.githubusercontent.com/u/100214298?v=4)](https://github.com/go-sleep "go-sleep (8 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/topphp-topphp-rsa/health.svg)

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

###  Alternatives

[mews/purifier

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

2.0k18.7M143](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24820.0k37](/packages/paragonie-ecc)

PHPackages © 2026

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