PHPackages                             juanchosl/cryptology - 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. juanchosl/cryptology

ActiveLibrary[Security](/categories/security)

juanchosl/cryptology
====================

Little encrypt/decrypt tools in order to crypt, decrypt, sign or verify messages, tests or files using distincts formats with the same way

1.0.1(9mo ago)164MITPHPPHP ^7.1 || ^8.0

Since Oct 15Pushed 9mo ago1 watchersCompare

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

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

Description
===========

[](#description)

This library brings together different reversible encryption systems, keeping the parameterization unified with the idea of ​​being able to change systems without maintenance in the code, simply adapting the constructions of the instances

Instalation
===========

[](#instalation)

use composer in order to install it

```
composer require juanchosl\cryptology
```

Types
=====

[](#types)

Open SSL
--------

[](#open-ssl)

### Symmetric Password

[](#symmetric-password)

The same password in plain text format for encode and decode, all receivers need to know the password

#### Options

[](#options)

- cipher: a cipher algorithm available, can check the response from openssl\_get\_cipher\_methods()

#### Examples

[](#examples)

```
$crypter = new Password;
$crypter->setPassword('myPassword');
$crypted_message = $crypter->encrypt('A message to encrypt');

$decrypter = new Password;
$decrypter->setPassword('myPassword');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

### Asymmetric PrivateKey/PublicKey

[](#asymmetric-privatekeypublickey)

One to one, if the sender encode using the privatekey, the receiver needs to decode using the related public key

#### Options

[](#options-1)

- padding: OPENSSL\_PKCS1\_PADDING or OPENSSL\_NO\_PADDING

#### Examples

[](#examples-1)

```
$crypter = new PrivateKey;
$crypter->setPrivateKey('/path/to/private_key.key');
$crypted_message = $crypter->encrypt('A message to encrypt');

$decrypter = new PublicKey;
$decrypter->setPublicKey('/path/to/public_key.pub');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

### Pkcs1

[](#pkcs1)

For all message types, send to some using public keys but generating an exclusive passphrase for each receiver, any one need to decode using his private key and the passphrase of the message

#### Options

[](#options-2)

- cipher: a cipher algorithm available, can check the response from openssl\_get\_cipher\_methods()
- algo: an algorithm method available, can check the response from openssl\_get\_md\_methods()

#### Examples

[](#examples-2)

```
$crypter = new Pkcs1;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response

$decrypter = new Pkcs1;
$decrypter->setPrivateKey('/path/to/my/private_key.key');
$decrypter->setPublicKey('/path/to/public_key.pub');
$decrypter->setPassword('message_password');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

You can sign the sended message with your own private key in order to ensure your identity

```
$crypter = new Pkcs1;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypter->setPrivateKey('/path/to/my/private_key.key');
$signed_message = $crypter->sign('A message to sign');
```

And verify the received message using the sender certificate

```
$decrypter = new Pkcs1;
$decrypter->setRemotes(['/path/to/sender/certificate.crt']);
$message = $decrypter->verify($signed_message);
```

### Pkcs7

[](#pkcs7)

For SMIME messages, send to some using receivers certificates and decode using the private key. We can sign the messages in order to apply a certification of sender

#### Options

[](#options-3)

- cipher: a cipher constant from openssl, by default OPENSSL\_CIPHER\_AES\_256\_CBC

#### Examples

[](#examples-3)

```
$crypter = new Pkcs7;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypted_message = $crypter->encrypt('A message to encrypt');

$decrypter = new Pkcs7;
$decrypter->setPrivateKey('/path/to/my/private_key.key');
$decrypter->setCertificate('/path/to/my/certificate.crt');
$decrypter->setRemotes(['/path/to/sender/certificate.crt']);
$decrypted_message = $decrypter->decrypt($crypted_message);
```

You can sign the sended message with your own private key in order to ensure your identity

```
$crypter = new Pkcs7;
$crypter->setPrivateKey('/path/to/my/private_key.key');
$crypter->setCertificate('/path/to/my/certificate.crt');
$signed_message = $crypter->sign('A message to encrypt');
```

And verify the received message using the sender certificate

```
$decrypter = new Pkcs7;
$decrypter->setRemotes(['/path/to/sender/certificate.crt']);
$message = $decrypter->verify($signed_message);
```

### CMS

[](#cms)

For multipurpose messages, send to some using receivers certificates and decode using our own private key and certificate. We can sign the messages in order to apply a certification of sender

#### Options

[](#options-4)

- encoding: OPENSSL\_ENCODING\_PEM, OPENSSL\_ENCODING\_SMIME or OPENSSL\_ENCODING\_DER (by default)
- cipher: a cipher constant from openssl, by default OPENSSL\_CIPHER\_AES\_256\_CBC

#### Examples

[](#examples-4)

```
$crypter = new Cms;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response

$decrypter = new Cms;
$decrypter->setPrivateKey('/path/to/my/private_key.key');
$decrypter->setCertificate('/path/to/my/certificate.crt');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

You can sign the sended message with your own private key in order to ensure your identity

```
$crypter = new Cms;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypter->setPrivateKey('/path/to/my/private_key.key');
$decrypter->setCertificate('/path/to/my/certificate.crt');
$signed_message = $crypter->sign('A message to sign');
```

And verify the received message using the sender certificate

```
$decrypter = new Cms;
$decrypter->setRemotes(['/path/to/sender/certificate.crt']);
$message = $decrypter->verify($signed_message);
```

Gpg
---

[](#gpg)

For use the Open GPG standard

### Gnupg

[](#gnupg)

Require the gnupg library installed for php

#### Examples

[](#examples-5)

```
$crypter = new Gnupg;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response

$decrypter = new Gnupg;
$decrypter->setPrivateKey('/path/to/my/private_key.key');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

You can sign the sended message with your own private key in order to ensure your identity

```
$crypter = new Gnupg;
$crypter->setRemotes(['/path/to/receiver/certificate.crt']);
$crypter->setPrivateKey('/path/to/my/private_key.key');
$signed_message = $crypter->sign('A message to sign');
```

And verify the received message using the sender certificate

```
$decrypter = new Gnupg;
$decrypter->setPrivateKey('/path/to/my/private_key.key');
$decrypter->setRemotes(['/path/to/sender/certificate.crt']);
$message = $decrypter->verify($signed_message);
```

### GpgConsole

[](#gpgconsole)

Require the gpg library installed for console

#### Examples

[](#examples-6)

```
$crypter = new GpgConsole;
$crypter->setRemotes(['receiver_fingerprint']);
$crypted_message = $crypter->encrypt('A message to encrypt');//An array with the crypted message in first position and an array with the passphrases as second element of the response

$decrypter = new GpgConsole;
$decrypter->setPrivateKey('private_fingerprint');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

You can sign the sended message with your own private key in order to ensure your identity

```
$crypter = new GpgConsole;
$crypter->setPrivateKey('private_fingerprint');
$crypter->setRemotes(['receiver_fingerprint']);
$signed_message = $crypter->sign('A message to sign');
```

And verify the received message using the sender certificate

```
$decrypter = new GpgConsole;
$decrypter->setPrivateKey('private_fingerprint');
$decrypter->setRemotes(['sender_fingerprint']);
$message = $decrypter->verify($signed_message);
```

Older systems
-------------

[](#older-systems)

We add an older type of encryption in order to be able to mantain our systems

### Mcrypt

[](#mcrypt)

The same password in plain text format for encode and decode, all receivers need to know the password

```
$crypter = new Mcrypt;
$crypter->setPassword('myPassword');
$crypted_message = $crypter->encrypt('A message to encrypt');

$decrypter = new Mcrypt;
$decrypter->setPassword('myPassword');
$decrypted_message = $decrypter->decrypt($crypted_message);
```

Utils
-----

[](#utils)

For create a GPG key use the console and follow the instructions, updating the phpunit.xml with the new credentials

```
root@1be56db22035:/application# gpg --full-generate-key
gpg (GnuPG) 2.2.40; Copyright (C) 2022 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
  (14) Existing key from card
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 1024
Requested keysize is 1024 bits
Please specify how long the key should be valid.
         0 = key does not expire
        = key expires in n days
      w = key expires in n weeks
      m = key expires in n months
      y = key expires in n years
Key is valid for? (0) 365
Key expires at Wed Oct 15 17:10:13 2025 UTC
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: Juan Sanchez
Email address: JuanchoSL@hotmail.com
Comment: Cryptology
You selected this USER-ID:
    "Juan Sanchez (Cryptology) "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: directory '/root/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/root/.gnupg/openpgp-revocs.d/572A0A03F67FD96351BBF7F3FC869096CAF45839.rev'
public and secret key created and signed.

pub   rsa1024 2024-10-15 [SC] [expires: 2025-10-15]
      572A0A03F67FD96351BBF7F3FC869096CAF45839
uid                      Juan Sanchez (Cryptology)
sub   rsa1024 2024-10-15 [E] [expires: 2025-10-15]
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance56

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

2

Last Release

294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd6d3dea7eb469817524c42a80683e95793ed4800a6794366503355af046a726?d=identicon)[Juanchosl](/maintainers/Juanchosl)

---

Top Contributors

[![JuanchoSL](https://avatars.githubusercontent.com/u/18701207?v=4)](https://github.com/JuanchoSL "JuanchoSL (16 commits)")

---

Tags

encryptdecryptopensslcmsmcryptcryptgpgpkcs7smimegnupgPKCS1cryptology

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/juanchosl-cryptology/health.svg)

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

###  Alternatives

[miladrahimi/phpcrypt

Encryption, decryption, and hashing tools for PHP projects

3171.5k2](/packages/miladrahimi-phpcrypt)[pear/crypt_gpg

Provides an object oriented interface to the GNU Privacy Guard (GnuPG). It requires the GnuPG executable to be on the system.

954.4M10](/packages/pear-crypt-gpg)[xxtea/xxtea

XXTEA is a fast and secure encryption algorithm. This is a XXTEA library for PHP.

11341.7k](/packages/xxtea-xxtea)[hemiframe/php-aes

PHP class for encrypt and decrypt data with AES algorithm

1030.3k](/packages/hemiframe-php-aes)[mpyw/easycrypt

A class that provides simple interface for decryptable encryption.

234.7k](/packages/mpyw-easycrypt)[poly-crypto/poly-crypto

High-level cryptographic functions that are interoperable between NodeJS and PHP 7.1+

127.8k1](/packages/poly-crypto-poly-crypto)

PHPackages © 2026

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