PHPackages                             phpgt/cipher - 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. phpgt/cipher

ActiveLibrary[Security](/categories/security)

phpgt/cipher
============

Two-way encryption of messages for secure plain text transmission.

v1.0.2(4mo ago)01.0k↑66.7%[2 PRs](https://github.com/PhpGt/Cipher/pulls)PHPPHP &gt;=8.4CI passing

Since Apr 18Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/PhpGt/Cipher)[ Packagist](https://packagist.org/packages/phpgt/cipher)[ GitHub Sponsors](https://github.com/sponsors/PhpGt)[ RSS](/packages/phpgt-cipher/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (8)Versions (20)Used By (0)

Two-way encryption of messages for secure plain text transmission.
==================================================================

[](#two-way-encryption-of-messages-for-secure-plain-text-transmission)

When messages are passed between two systems over a public network, encryption tools are needed to protect the content in transit. Encrypting and decrypting messages correctly can be fiddly and error-prone, so this library keeps the process small and explicit through the `PlainTextMessage`, `EncryptedMessage`, `CipherText`, `Key`, and `InitVector` abstractions.

Pass your secret message to the `PlainTextMessage` constructor, then call `encrypt()` with a shared `Key` to produce a `CipherText`. The encrypted payload is represented by the cipher text itself plus the IV returned by `getIv()`. Those values can then be passed to the receiver by any communication mechanism, with only the holder of the same shared key able to decrypt the original message.

On the receiving side, construct an `EncryptedMessage` with the incoming cipher text and IV, then call `decrypt()` with the same `Key` to recover the original plain text.

The `CipherText` class also provides a `getUri()` method for creating a pre-encoded URI. A URI containing `cipher` and `iv` query string parameters can then be passed to `EncryptedUri` and decrypted back into a `PlainTextMessage`.

---

[ ![Build status](https://camo.githubusercontent.com/e18af1c9d4c231ecf7c044010b28dc79e56acf8c48007be58f7b965ea3c98871/68747470733a2f2f62616467652e7374617475732e7068702e67742f6369706865722d6275696c642e737667)](https://github.com/PhpGt/Cipher/actions)[ ![Code quality](https://camo.githubusercontent.com/bfd8f22f663cfba1c8b439cea6792ce4fa9281415f8bef2d744616ce8e0b3521/68747470733a2f2f62616467652e7374617475732e7068702e67742f6369706865722d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/Cipher)[ ![Code coverage](https://camo.githubusercontent.com/6473098ed3fb0766f8c4aae97372fcf9a58b49f59a2d83313ec1c0eaef65bbc8/68747470733a2f2f62616467652e7374617475732e7068702e67742f6369706865722d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/Cipher)[ ![Current version](https://camo.githubusercontent.com/1be77c118cd78954434c5686f5fa964051581997d5444b4e0f8e8970cfecb6a6/68747470733a2f2f62616467652e7374617475732e7068702e67742f6369706865722d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/Cipher)[ ![PHP.Gt/Cipher documentation](https://camo.githubusercontent.com/271e40d1f797672495efe98c2b3e5dab4286c4366a300ad902f0792b4c4f4374/68747470733a2f2f62616467652e7374617475732e7068702e67742f6369706865722d646f63732e737667)](http://www.php.gt/cipher)Example usage: transmit an encrypted message over a query string
----------------------------------------------------------------

[](#example-usage-transmit-an-encrypted-message-over-a-query-string)

`sender.php`:

```
use \GT\Cipher\Message\PlainTextMessage;
use \GT\Cipher\Message\EncryptedMessage;

$privateKey = "This can be any string, but a long random string is best.";

$message = new PlainTextMessage("Hello, PHP.Gt!");
$cipherText = $message->encrypt($privateKey);
header("Location: " . $cipherText->getUri("/receiver.php"));
```

`receiver.php`:

```
// This key must be the same on the sender and receiver!
use GT\Cipher\EncryptedUri;

$privateKey = "This can be any string, but a long random string is best.";

$uri = new EncryptedUri($_SERVER["REQUEST_URI"]);
$plainText = $uri->decryptMessage($privateKey);
echo $plainText;
// Output: Hello, PHP.Gt!
```

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance85

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~292 days

Recently: every ~347 days

Total

6

Last Release

120d ago

Major Versions

v0.3.0 → v1.0.02022-07-20

PHP version history (2 changes)v0.1.0PHP &gt;=8.0

v1.0.2PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (9 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgt-cipher/health.svg)

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

###  Alternatives

[phpids/phpids

PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web application

791150.0k2](/packages/phpids-phpids)[paragonie/ecc

PHP Elliptic Curve Cryptography library

25866.3k44](/packages/paragonie-ecc)[nicobleiler/php-passphrase

Passphrase generator with Laravel integration, inspired by Bitwarden. Uses the EFF long word list by default with support for custom wordlists.

4912.6k](/packages/nicobleiler-php-passphrase)[phpgt/webengine

Minimalistic, ergonomic PHP toolkit.

2722.4k](/packages/phpgt-webengine)[dwgebler/encryption

Encryption wrapper for PHP using libsodium — simple API for symmetric and asymmetric encryption, password hashing, digital signing, and message authentication.

317.5k](/packages/dwgebler-encryption)

PHPackages © 2026

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