PHPackages                             benjaminstout/php-crypt - 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. benjaminstout/php-crypt

ActiveLibrary

benjaminstout/php-crypt
=======================

Barebones Cryptography Library for PHP – libsodium (NaCl), OpenSSL, Mcrypt, and more

v1.0(7y ago)2421MITPHPPHP &gt;=5.6.0CI failing

Since Apr 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/benjaminstout/PHP-Crypt)[ Packagist](https://packagist.org/packages/benjaminstout/php-crypt)[ RSS](/packages/benjaminstout-php-crypt/feed)WikiDiscussions master Synced 2mo ago

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

PHP-Crypt
=========

[](#php-crypt)

[![](https://camo.githubusercontent.com/b4dc127c5ea67e33ea16f896aa3d643d0030adb1d9784deb798d443904e47f67/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d626574612d626c75652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/b4dc127c5ea67e33ea16f896aa3d643d0030adb1d9784deb798d443904e47f67/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73746162696c6974792d626574612d626c75652e7376673f7374796c653d666c61742d737175617265) [![build:](https://camo.githubusercontent.com/5da1eb1ed5a669ead0d51dc008d4157d0282d23647e7e1e8115258afea0d9879/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f73746f75747075742f5048502d43727970742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/stoutput/PHP-Crypt) [![](https://camo.githubusercontent.com/59d6d92617be169f4f0483c2d47a901f70b675d675d0f453732d313f21da8e3c/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f73746f75747075742f7068702d63727970742e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/stoutput/php-crypt) [![](https://camo.githubusercontent.com/89a68b202eee0330f790f8e7d8989fe23792b37e3f3b89ea2c5a40f35be2b558/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f73746f75747075742f7068702d63727970742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/89a68b202eee0330f790f8e7d8989fe23792b37e3f3b89ea2c5a40f35be2b558/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f73746f75747075742f7068702d63727970742e7376673f7374796c653d666c61742d737175617265) [![](https://camo.githubusercontent.com/e7b98e3c62131b3168e2a3a14fd69eb37aff88818254a1872e800f1f50080426/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f73746f75747075742f7068702d63727970742e7376673f636f6c6f723d253233333037414245267374796c653d666c61742d737175617265)](LICENSE.txt)

A standalone, extensible, lightweight cryptography interface for PHP. With support for: [libsodium](https://github.com/jedisct1/libsodium) (NaCl), [OpenSSL](http://php.net/manual/en/book.openssl.php), [Mcrypt](http://php.net/manual/en/book.mcrypt.php), and more.

PHP-Crypt allows you to quickly integrate a suite of modern cryptographic libraries into your PHP application, without the hassle of implementing advanced custom cryptographic methods by hand. PHP-Crypt prevents common cryptographic pitfalls, while providing the flexibility to choose between a suite of the latest cryptography libraries available for PHP. Usage is straightforward and highly extensible – comprised only of the minimum complexity necessary to ensure optimal security. PHP-Crypt makes swapping or integrating new cryptography libraries a breeze!

- PHP-Crypt features [*authenticated encryption*](https://en.wikipedia.org/wiki/Authenticated_encryption) straight out of the box (with [Sodium](https://libsodium.gitbook.io/doc/secret-key_cryptography/authenticated_encryption) or [OpenSSL](https://wiki.openssl.org/index.php/EVP_Authenticated_Encryption_and_Decryption))
- PHP-Crypt is easily extensible – just drop an implementation of your favorite cryptography library into src/lib, and call `new Crypt('')` when instantiating PHP-Crypt. It couldn't be easier! While you're at it, [submit a PR](https://github.com/stoutput/php-crypt/pull/new/master)!

Prerequisites
-------------

[](#prerequisites)

- PHP &gt;= 5.6
- If on PHP &lt; 7.2, [install libsodium and the sodium PHP extension](https://paragonie.com/book/pecl-libsodium/read/00-intro.md) to enable full support for the Sodium library.
- If on PHP &gt;= 7.2, [install the Mcrypt PHP extension through PECL](https://pecl.php.net/package/mcrypt) to enable support for Mcrypt. Note: production usage of Mcrypt is *highly* discouraged, and should only be used for backwards compatability.
- Composer

Installation
------------

[](#installation)

PHP-Crypt supports installation in your PHP app through either [composer](https://getcomposer.org/) or [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules).

**Composer**: `composer require benjaminstout/php-crypt`
**Git**: `git add submodule git@github.com:stoutput/php-crypt.git  && composer update -d `

```
use BenjaminStout\PHPCrypt\Crypt;
require_once '/src/Crypt.php';
```

Getting Started
---------------

[](#getting-started)

**Instantiate a new instance of PHP-Crypt**:

```
$this->Crypt = new Crypt('', '');
```

*Where*:
`` is the cryptography library to use (Sodium \[default\], Openssl, Mcrypt, ...)
`` is an *optional* key string to use for encryption. It must adhere to library's key requirements.

**Encrypt a string**:

```
$this->Crypt->encrypt('string');
```

**Decrypt ciphertext**:

```
$this->Crypt->decrypt('eNcRyPtEd');
```

Encryption Keys
---------------

[](#encryption-keys)

If the encryption key is left unspecified during instantiation, PHP-Crypt will look for an existing key located first at `Config::$config['keyPath']` and then `Config::$config['keyPath']`. If no existing key is found, PHP-Crypt automatically generates and saves a suitable random key for use by the library.

For security purposes, keys are stored in the filesystem well outside of WWW\_ROOT by default. Existing key files should be **lowercase**, with a suffix of `.key`, and named after the library to which they belong. Ex: `keyPathOpenssl => 'openssl.key'`.

### *Examples*:

[](#examples)

- Allowing PHP-Crypt to generate your keys for you without any pre-existing key file:

    ```
    $this->Crypt = new Crypt('Openssl');
    ```

    automatically saves the generated random key to `openssl.key` under `Config::$config['keyPath']`.
- Whereas, passing a key into the constructor will create an alternate `.custom.key` file (to avoid overwriting pre-existing keys). For example:

    ```
    $this->Crypt = new Crypt('Openssl', 'KeY123');
    ```

    Creates a file under `Config::$config['keyPath']` named openssl.custom.key with the contents `KeY123`.
- If you wish to specify a unique path to a key for a library to use, pass in a value for `'keyPath'` during instantiation:

    ```
    $this->Crypt = new Crypt('Openssl', [
        'keyPathOpenssl' => '/path/to/openssl.key',
    ]);
    ```

    or, set it afterwards:

    ```
    Crypt::setKeyPath('Openssl', '/path/to/openssl.key');
    ```

Testing
-------

[](#testing)

Run a `composer update --dev` to install phpunit in the project, then run `vendor/bin/phpunit` from the root of the project.

Contributing
------------

[](#contributing)

All contributions are welcome and encouraged! Start a discussion by [opening an issue](https://github.com/stoutput/php-crypt/issues/new), then fork this repo, commit your work, and [submit a PR](https://github.com/stoutput/php-crypt/pull/new/master)!

Important Notes
---------------

[](#important-notes)

Use of the Mcrypt library is ***highly*** disadvised, and is only included in PHP-Crypt for backwards compatability. The underlying library (libmcrypt) has been abandoned since 2007, and contains a host of undesirable behaviors and possible vulnerabilities. Instead, use Sodium or OpenSSL.

License
-------

[](#license)

This project is licensed under the terms of the [MIT license](LICENSE.txt).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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

Unknown

Total

1

Last Release

2572d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54e81df9d28ed8bf4f08c5859d99d5d38ac4499cc5d5b5d6c5633551bd4061ac?d=identicon)[benjaminstout](/maintainers/benjaminstout)

---

Top Contributors

[![stoutput](https://avatars.githubusercontent.com/u/13671824?v=4)](https://github.com/stoutput "stoutput (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/benjaminstout-php-crypt/health.svg)

```
[![Health](https://phpackages.com/badges/benjaminstout-php-crypt/health.svg)](https://phpackages.com/packages/benjaminstout-php-crypt)
```

###  Alternatives

[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k434.8M1.3k](/packages/phpseclib-phpseclib)[mpdf/mpdf

PHP library generating PDF files from UTF-8 encoded HTML

4.7k77.1M490](/packages/mpdf-mpdf)[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M212](/packages/defuse-php-encryption)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[paragonie/halite

High-level cryptography interface powered by libsodium

1.2k9.4M63](/packages/paragonie-halite)[fedeisas/laravel-mail-css-inliner

Inline the CSS of your HTML emails using Laravel

5974.6M3](/packages/fedeisas-laravel-mail-css-inliner)

PHPackages © 2026

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