PHPackages                             jdz/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jdz/crypt

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jdz/crypt
=========

Simple Crypt/Decrypt utility

3.0.2(2mo ago)020MITPHPPHP &gt;=8.2

Since Dec 3Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/joffreydemetz/crypt)[ Packagist](https://packagist.org/packages/jdz/crypt)[ Docs](https://jdz.joffreydemetz.com/crypt)[ RSS](/packages/jdz-crypt/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)Dependencies (2)Versions (9)Used By (0)

Crypt
=====

[](#crypt)

Simple crypt/decrypt utility

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

[](#installation)

To install the package, you can use Composer:

```
composer require jdz/crypt
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer for dependency management

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
use JDZ\Crypt\Crypt;
use JDZ\Crypt\SimpleCipher;
use JDZ\Crypt\Key;

// Create a key
$key = new Key('my-secret-passphrase');

// Create cipher and crypt instances
$cipher = new SimpleCipher();
$crypt = new Crypt($cipher, $key);

// Encrypt
$originalText = 'Secret message';
$encrypted = $crypt->encrypt($originalText);

// Decrypt
$decrypted = $crypt->decrypt($encrypted);

echo $decrypted; // Output: Secret message
```

### Available Ciphers

[](#available-ciphers)

The library provides three cipher implementations:

1. **SimpleCipher** - Uses the passphrase directly as the encryption key
2. **Md5Cipher** - Uses MD5 hash of the passphrase (32 characters)
3. **Sha1Cipher** - Uses SHA1 hash of the passphrase (40 characters)

All ciphers use XOR-based encryption and extend from `SimpleCipher`.

### Key Generation

[](#key-generation)

You can generate keys automatically using the generator classes:

```
use JDZ\Crypt\SimpleGenerator;
use JDZ\Crypt\Md5Generator;
use JDZ\Crypt\Sha1Generator;

// Simple generator
$generator = new SimpleGenerator();
$key = $generator->generateKey();

// MD5 generator
$md5Generator = new Md5Generator();
$md5Key = $md5Generator->generateKey();

// SHA1 generator
$sha1Generator = new Sha1Generator();
$sha1Key = $sha1Generator->generateKey();
```

### Manual Key Creation

[](#manual-key-creation)

```
use JDZ\Crypt\Key;

// Single key (public and private are the same)
$key = new Key('my-passphrase');

// Separate public and private keys
$key = new Key('public-key', 'private-key');
```

Examples
--------

[](#examples)

The `examples/` directory contains:

- **simple.php** - Basic usage with SimpleCipher and key generation
- **md5.php** - MD5-based encryption with auto-generated and manual keys
- **sha1.php** - SHA1-based encryption with auto-generated and manual keys
- **comparison.php** - Comparison of all cipher types
- **benchmark.php** - Performance comparison and timing benchmarks

Run an example:

```
php examples/simple.php
php examples/md5.php
php examples/sha1.php
```

Compare and benchmark:

```
php examples/comparison.php
php examples/benchmark.php
```

Testing
-------

[](#testing)

### Run Tests

[](#run-tests)

Run all tests:

```
composer test
# or
vendor/bin/phpunit
```

Run tests with coverage report (HTML):

```
composer test-coverage
# Coverage report will be generated in the coverage/ directory
```

### Test Structure

[](#test-structure)

Tests are located in the `tests/` directory and follow the PSR-4 autoloading standard under the `JDZ\Crypt\Tests` namespace.

- `KeyTest.php` - Tests for the Key class
- `SimpleCipherTest.php` - Tests for the SimpleCipher implementation
- `CryptTest.php` - Tests for the main Crypt class

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance84

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

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

Recently: every ~722 days

Total

7

Last Release

83d ago

Major Versions

1.2.0 → 2.0.02018-05-13

2.0.1 → 3.0.02025-12-03

PHP version history (4 changes)1.1.0PHP &gt;=5.6

2.0.0PHP ^7.1.3

3.0.0PHP &gt;=8.1

3.0.2PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e83e3701566e43438525ed14578487e732b849d152b5071aa1613a0dad96913?d=identicon)[jdz](/maintainers/jdz)

---

Top Contributors

[![joffreydemetz](https://avatars.githubusercontent.com/u/15113527?v=4)](https://github.com/joffreydemetz "joffreydemetz (17 commits)")

---

Tags

corecryptutilitiesJDZ

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k417.9M1.7k](/packages/nette-utils)[fidry/cpu-core-counter

Tiny utility to get the number of CPU cores.

243171.4M36](/packages/fidry-cpu-core-counter)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

3014.6M24](/packages/vaimo-composer-patches)[typo3/cms-composer-installers

TYPO3 CMS Installers

6114.3M66](/packages/typo3-cms-composer-installers)[kartik-v/yii2-helpers

A collection of useful helper functions for Yii Framework 2.0

933.1M29](/packages/kartik-v-yii2-helpers)

PHPackages © 2026

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