PHPackages                             jaquarh/phpencrypter - 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. jaquarh/phpencrypter

ActiveLibrary[Security](/categories/security)

jaquarh/phpencrypter
====================

Encrypt and Sign data in PHP with ease

001PHP

Since Dec 20Pushed 5y agoCompare

[ Source](https://github.com/Jaquarh/PHPEncrypter)[ Packagist](https://packagist.org/packages/jaquarh/phpencrypter)[ RSS](/packages/jaquarh-phpencrypter/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPEncrypter
============

[](#phpencrypter)

PHPEncrypter is an open source library utilising LibSodium to encrypt data between parties and sign data.

Current Version
===============

[](#current-version)

1.0.2 - Added base64 mutual translator to allow for encryption of arrays and objects.

Installation
============

[](#installation)

```
composer require jaquarh/phpencrypter
```

[LibSodium Installation](http://php.net/manual/en/sodium.installation.php) requries enabling the extension in your php.ini configuration or by compiling your PHP source with the LibSodium configuration option.

As of PHP 7.2.0 this extension is bundled with PHP. For older PHP versions this extension is available via PECL.

Once you have enabled the extension, you can now clone the repository. Simply create a class and use the Cipher.

```
class MyFirstCipher
{
    use \Cipher\Cipher;
}
```

Demo Scenario
=============

[](#demo-scenario)

Here is an example of a real life situation. Bob wants to send Alice a secret message, he encrypts and signs his message. Alice then reads the message.

```
    public function demo()
    {
        # Issue keys (would be stored in the database and retrieved as needed)
        $bob   = $this->issueKeys();
        $alice = $this->issueKeys();

        # Encrypt a message from Bob to Alice
        $cipher = $this->encrypt($alice->public, $bob->private, 'This is a test message');

        # Sign the message and send
        $bobSig    = $this->issueSignatureKeys();
        $signature = $this->signMessage($cipher->cipher, $bobSig->private);

        # Alice now verifies the message using the signature sent
        if($this->verifySignature($signature, $bobSig->public))
        {
            # Decrypt the message that was also sent along with the signature and nonce
            echo $this->decrypt($alice->private, $bob->public, $cipher->cipher, $cipher->nonce);
        }
    }
```

Generating your keys
====================

[](#generating-your-keys)

In order to generate your key pair, you must use the `issueKeys()` method. Each user, or party, must have a key pair which is split down into public and private for ease of use.

```
class MyFirstCipher
{
    use \Cipher\Cipher;

    private $userOne = [], $userTwo = [];

    public function __construct()
    {
        $this->userOne['kp'] = $this->issueKeys();
        $this->userTwo['kp'] = $this->issueKeys();
    }
}
```

Encrypting messages
===================

[](#encrypting-messages)

In order to encrypt a message, you must know which user, or party, the message is being sent too. We use the 3rd parties public key to encrypt the data and our own to sign. For example, if userOne wants to send userTwo a message, he can do so like so.

```
class MyFirstCipher
{
    use \Cipher\Cipher;

    private $userOne = [], $userTwo = [];

    public function __construct()
    {
        $this->userOne['kp'] = $this->issueKeys();
        $this->userTwo['kp'] = $this->issueKeys();
    }

    public function sendMessage()
    {
        return $this->encrypt($this->userTwo['kp']->public, $this->userOne['kp']->private, 'User ones secret message to user two');
    }
}
```

Decrypting the message
======================

[](#decrypting-the-message)

In order to decrypt the message that userOne has sent, we must know who sent the message. Using our private key and the 3rd parties public key, we are able to decrypt the message like so.

```
class MyFirstCipher
{
    use \Cipher\Cipher;

    private $userOne = [], $userTwo = [];

    public function __construct()
    {
        $this->userOne['kp'] = $this->issueKeys();
        $this->userTwo['kp'] = $this->issueKeys();
    }

    public function sendMessage()
    {
        # Returns an object ->cipher & ->nonce
        return $this->encrypt($this->userTwo['kp']->public, $this->userOne['kp']->private, 'User ones secret message to user two');
    }

    public function readMessage($cipher, $nonce)
    {
        return $this->decrypt($this->userTwo['kp']->private, $this->userOne['kp']->public, $cipher, $nonce);
    }
}
```

Signing the encrypted message
=============================

[](#signing-the-encrypted-message)

In order to verify that the message came from the user, we can sign the message before sending it.

```
class MyFirstCipher
{
    use \Cipher\Cipher;

    private $userOne = [], $userTwo = [];

    public function __construct()
    {
        $this->userOne['kp'] = $this->issueKeys();
        $this->userTwo['kp'] = $this->issueKeys();

        # Lets issue signature keys
        $this->userOne['skp'] = $this->issueSignatureKeys();
    }

    public function sendMessageAndSign()
    {
        return (object) [
            'cipher'    => ($cipher = $this->encrypt($this->userTwo['kp']->public, $this->userOne['kp']->private, 'User ones secret message to user two')),
            'signature' => $this->signMessage($cipher->cipher, $this->userOne['skp']->private)
        ];
    }
}
```

Verifying a signature
=====================

[](#verifying-a-signature)

```
class MyFirstCipher
{
    use \Cipher\Cipher;

    private $userOne = [], $userTwo = [];

    public function __construct()
    {
        $this->userOne['kp']  = $this->issueKeys();
        $this->userTwo['kp']  = $this->issueKeys();
        $this->userOne['skp'] = $this->issueSignatureKeys();
    }

    public function verifyEncryption($signature)
    {
        return $this->verifySignature($signature, $this->userOne['skp']->public);
    }
}
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

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/dab513f2c318ab7db959b6df9e6bc655ed62ca1eef7c25adf96c8e17cc553d0e?d=identicon)[Kyle Jeynes](/maintainers/Kyle%20Jeynes)

---

Top Contributors

[![Jaquarh](https://avatars.githubusercontent.com/u/40298132?v=4)](https://github.com/Jaquarh "Jaquarh (14 commits)")

### Embed Badge

![Health badge](/badges/jaquarh-phpencrypter/health.svg)

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

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

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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