PHPackages                             lithemod/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. [Security](/categories/security)
4. /
5. lithemod/crypt

ActiveLibrary[Security](/categories/security)

lithemod/crypt
==============

A lightweight encryption utility for PHP applications, providing secure data encryption and decryption functionalities.

v2.0.0(1y ago)017MITPHPPHP ^8.0

Since Oct 2Pushed 1y agoCompare

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

READMEChangelogDependencies (3)Versions (3)Used By (0)

Lithe Crypt
===========

[](#lithe-crypt)

Lithe Crypt is a simple encryption and decryption utility for PHP, designed to work with the Lithe framework. It utilizes the AES-256-CBC algorithm for secure data handling.

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

[](#installation)

To install the Lithe Crypt package, you can use Composer. If you haven't already, make sure you have Composer installed. Then run the following command in your project directory:

```
composer require lithemod/crypt
```

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

[](#requirements)

- **PHP 8 or higher**
- **OpenSSL extension** enabled in your PHP installation

Usage
-----

[](#usage)

### Loading Environment Variables

[](#loading-environment-variables)

Before using the Crypt class, you need to load your environment variables. Use the following code to load your `.env` file:

```
use Lithe\Support\Env;

// Load environment variables
Env::load(__DIR__); // Adjust the path as necessary
```

### Setting the APP\_KEY

[](#setting-the-app_key)

Ensure that the `APP_KEY` environment variable is set. This key should be a base64 encoded string of 32 bytes. You can configure it in your `.env` file or directly in your server environment.

**Example of a valid base64 key:**

```
YXNkZmFnc2Rhc2RmYWdlcyBhc2RmYWdlcyBhYXNkZmFnc2Q=

```

### Encrypting Data

[](#encrypting-data)

To encrypt data, use the `encrypt` method of the Crypt class. You can also specify whether you want to use a fixed IV (initialization vector) for encryption:

```
use Lithe\Support\Security\Crypt;

$data = "sensitive data";

// Encrypt without fixed IV
$encrypted = Crypt::encrypt($data);
echo "Encrypted Data: " . $encrypted;

// Encrypt with fixed IV (useful for unique values like emails)
$encryptedWithSameIV = Crypt::encrypt($data, true);
echo "Encrypted Data with Fixed IV: " . $encryptedWithSameIV;
```

### Decrypting Data

[](#decrypting-data)

To decrypt the previously encrypted data, use the `decrypt` method. You must specify the same parameters used during encryption to ensure proper decryption:

```
use Lithe\Support\Security\Crypt;

// Decrypt without fixed IV
$decrypted = Crypt::decrypt($encrypted);
echo "Decrypted Data: " . $decrypted;

// Decrypt with fixed IV
$decryptedWithSameIV = Crypt::decrypt($encryptedWithSameIV, true, $data);
echo "Decrypted Data with Fixed IV: " . $decryptedWithSameIV;
```

### Exception Handling

[](#exception-handling)

If the `APP_KEY` is not set or is invalid, the Crypt class will throw a `CryptException`. It's essential to handle this exception in your code to avoid unexpected errors:

```
use Lithe\Exceptions\Encryption\CryptException;

try {
    $encrypted = Crypt::encrypt($data);
    // Decrypt without fixed IV
    $decrypted = Crypt::decrypt($encrypted);
} catch (CryptException $e) {
    echo "Encryption Error: " . $e->getMessage();
}
```

Unit Tests
----------

[](#unit-tests)

To ensure the functionality of the Crypt class, unit tests are provided. You can run the tests using PHPUnit:

```
./vendor/bin/phpunit
```

### Test Cases

[](#test-cases)

- `testEncryptDecrypt`: Tests the encryption and decryption process.
- `testEncryptWithNullData`: Tests encryption with null data.
- `testEncryptWithSameIV`: Tests the behavior of encryption with a fixed IV.

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

[](#contributing)

If you would like to contribute to the Lithe Crypt project, please follow these guidelines:

1. Fork the repository.
2. Create a new branch for your feature or bug fix.
3. Write tests for your changes.
4. Submit a pull request with a clear description of your changes.

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Total

2

Last Release

588d ago

Major Versions

v1.0.0 → v2.0.02024-10-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/56173de3a7bf7099dd8168efd730d3c2fb5df5174a123fdc37cee8c3589e2345?d=identicon)[williamhumbwavali](/maintainers/williamhumbwavali)

---

Top Contributors

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

---

Tags

encryptionmodulephp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)
