PHPackages                             janfish/security - 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. janfish/security

ActiveLibrary

janfish/security
================

Encrypt、Decrypt、Sign、Verify with RSA

013PHP

Since Sep 27Pushed 3y ago1 watchersCompare

[ Source](https://github.com/zeng444/security)[ Packagist](https://packagist.org/packages/janfish/security)[ RSS](/packages/janfish-security/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Usage
=====

[](#usage)

RSA
---

[](#rsa)

#### Generate Rsa keys

[](#generate-rsa-keys)

> the available key lengths are 1024 and 2048

```
$ openssl genrsa -out rsa_private_key.pem 1024
$ openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem

```

#### Encrypt &amp; Sign

[](#encrypt--sign)

- prepare keys

```
$pri = file_get_contents('keys/rsa_private_key.pem');
$pub = file_get_contents('keys/rsa_public_key.pem');
```

- encrypt

```
$rsa = new RSA();
$rsa->setPubKey($pub);
$encodedData = $rsa->encrypt("hello", RSA::OPENSSL_PKCS1_PADDING);

```

- decrypt

```
$rsa = new RSA();
$rsa->setPriKey($pri);
$sourceData = $rsa->decrypt($encodedData, RSA::OPENSSL_PKCS1_PADDING);

```

- sign

```
$rsa = new RSA();
$rsa->setPriKey($pri);
$signedData = $rsa->sign('hello',Rsa::OPENSSL_ALGO_SHA256);

```

- verify

```
$rsa = new RSA();
$rsa->setPubKey($pri);
$result = $rsa->verify('hello',$signedData,Rsa::OPENSSL_ALGO_SHA256);

```

#### Support Params

[](#support-params)

- Signature Algorithm Type

namedefaultvalueOPENSSL\_ALGO\_SSHA1yes1OPENSSL\_ALGO\_SMD52OPENSSL\_ALGO\_SMD43OPENSSL\_ALGO\_SMD24OPENSSL\_ALGO\_SDSS15OPENSSL\_ALGO\_SSHA2246OPENSSL\_ALGO\_SSHA2567OPENSSL\_ALGO\_SSHA3848OPENSSL\_ALGO\_SSHA5129OPENSSL\_ALGO\_SRMD16010- Encryption Padding Type

namedefaultvaluePKCS1\_PKCS1\_PADDINGyes1PKCS1\_SSLV23\_PADDING2PKCS1\_NO\_PADDING3PKCS1\_OAEP\_PADDING4#### Tips

[](#tips)

- When OpenSSL is used "OPENSSL\_NO\_PADDING" to padding parameter, you need to manually fill in the original data

```
$str = str_pad("hello", 256); //128 or 256
$rsa = new RSA();
$rsa->setPubKey($pub);
$encodedData = $rsa->encrypt($str, RSA::OPENSSL_NO_PADDING);

```

Other Encryption
----------------

[](#other-encryption)

```
$encryption= new Crypt(['cipher' => 'aes-256-cbc']);
$encode = $encryption->encrypt("hello", 'keyToMyHeart');
$decode = $encryption->decrypt($encode, 'keyToMyHeart');
var_dump([
    $encryption->getIv(),
    $encode,
    $decode
]);

```

```

$en = new Crypt(['cipher' => 'aes-256-cbc']); //des-ede3;
$iv = '0123456789abcdef';
//$iv = $en->makeIv();
$clientSecret = 'nuasndu89382j3d3d9238';

$encode = $en->encrypt("hello", $clientSecret, $iv);
$decode = $en->decrypt($encode, $clientSecret, $iv);

var_dump([
    $en->getIv(),
    $en->ivSize,
    $encode,
    $decode
]);

```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/60a62fd9f299f25558ac4a898ae3833bd7185ba4706bb167a8cabf05a3d96955?d=identicon)[Robert Zeng](/maintainers/Robert%20Zeng)

---

Top Contributors

[![zeng444](https://avatars.githubusercontent.com/u/941266?v=4)](https://github.com/zeng444 "zeng444 (7 commits)")

### Embed Badge

![Health badge](/badges/janfish-security/health.svg)

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

PHPackages © 2026

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