PHPackages                             ahsankhatri/cryptolib-php - 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. ahsankhatri/cryptolib-php

ActiveLibrary[Security](/categories/security)

ahsankhatri/cryptolib-php
=========================

A library to encrypt or decrypt with random password generator based on secret key defined.

v2.0.0(2y ago)1568.7k↓34.9%10MITPHPPHP ^8.1

Since Dec 5Pushed 2y ago3 watchersCompare

[ Source](https://github.com/ahsankhatri/cryptolib-php)[ Packagist](https://packagist.org/packages/ahsankhatri/cryptolib-php)[ Docs](https://github.com/ahsankhatri/cryptolib-php)[ RSS](/packages/ahsankhatri-cryptolib-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

CryptoLib (PHP)
===============

[](#cryptolib-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2d111968176df89be7c126bafec145a594df3b09a1e675e8935e195c45297e83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616873616e6b68617472692f63727970746f6c69622d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahsankhatri/cryptolib-php)[![tests](https://github.com/ahsankhatri/cryptolib-php/actions/workflows/php-test.yml/badge.svg)](https://github.com/ahsankhatri/cryptolib-php/actions/workflows/php-test.yml/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/e102621e7c2cf96e76f1a728f8057989bf2134e264d86dcf9af2d32af0a135a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616873616e6b68617472692f63727970746f6c69622d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ahsankhatri/cryptolib-php)[![License](https://camo.githubusercontent.com/6cd55c8d680cc9062240cc7f76196c2cb409ede9774c6f5f0986e2164d97c42c/68747470733a2f2f706f7365722e707567782e6f72672f616873616e6b68617472692f63727970746f6c69622d7068702f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/ahsankhatri/cryptolib-php)

This is the library for encrypting data with a key (password will be generate as per your parameters set) in PHP.

**WHY ANOTHER LIBRARY?** This was intended to developed for cross-platform AES Encryption [here](https://github.com/skavinvarnan/Cross-Platform-AES) as PHP was missing. My main objective is to create library for `AES-256-CBC` to contribute PHP package for Cross-Platform-AES package, more features will be added whenever I gets time.

### Features

[](#features)

- Support for Random IV (initialization vector) for encryption and decryption. Randomization is crucial for encryption schemes to achieve semantic security, a property whereby repeated usage of the scheme under the same key does not allow an attacker to infer relationships between segments of the encrypted message.
- Support for SHA-256 for hashing the key. Never use plain text as encryption key. Always hash the plain text key and then use for encryption. AES permits the use of 256-bit keys. Breaking a symmetric 256-bit key by brute force requires 2^128 times more computational power than a 128-bit key. A device that could check a billion billion (10^18) AES keys per second would in theory require about 3×10^51 years to exhaust the 256-bit key space.
- PHP-7 Support since `mcrypt` has been deprecated.

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

[](#installation)

You can install the package via composer:

```
composer require ahsankhatri/cryptolib-php
```

Dependencies
------------

[](#dependencies)

The bindings require the following extensions in order to work properly:

- [`openssl`](https://secure.php.net/manual/en/book.openssl.php)

If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.

Usage
-----

[](#usage)

#### With Random IV

[](#with-random-iv)

```
$string     = 'The quick brown fox jumps over to the lazy dog.';
$secretyKey = 'BlVssQKxzAHFAUNZbqvwS+yKw/m';

$encryption = new \MrShan0\CryptoLib\CryptoLib();

$cipher  = $encryption->encryptPlainTextWithRandomIV($string, $secretyKey);
echo 'Cipher: ' . $cipher . PHP_EOL;

$plainText = $encryption->decryptCipherTextWithRandomIV($cipher, $secretyKey);
echo 'Decrypted: ' . $plainText . PHP_EOL;
```

#### With Generated IV

[](#with-generated-iv)

```
$string     = 'The quick brown fox jumps over to the lazy dog.';
$secretyKey = 'BlVssQKxzAHFAUNZbqvwS+yKw/m';

$encryption = new \MrShan0\CryptoLib\CryptoLib();
$iv         = $encryption->generateRandomIV();

$cipher = $encryption->encrypt($string, $secretyKey, $iv);
echo 'Cipher: ' . $cipher . PHP_EOL;

$plainText = $encryption->decrypt($cipher, $secretyKey, $iv);
echo 'Decrypted: ' . $plainText . PHP_EOL;
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ahsaan Muhammad Yousuf](https://ahsaan.me)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

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

Total

3

Last Release

882d ago

Major Versions

v1.1.0 → v2.0.02023-12-19

PHP version history (2 changes)v1.0.0PHP ^7.0

v2.0.0PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![ahsankhatri](https://avatars.githubusercontent.com/u/7288116?v=4)](https://github.com/ahsankhatri "ahsankhatri (1 commits)")

---

Tags

decryptionencryptionphpphp7rijndael-aes-cipherRijndaelaes-encryptioncryptolib

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ahsankhatri-cryptolib-php/health.svg)

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[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

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

Realistic password strength estimation PHP library based on Zxcvbn JS

87117.5M63](/packages/bjeavons-zxcvbn-php)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[paragonie/hidden-string

Encapsulate strings in an object to hide them from stack traces

7410.6M39](/packages/paragonie-hidden-string)

PHPackages © 2026

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