PHPackages                             ghalibilal/laravel-hmac-encryption - 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. ghalibilal/laravel-hmac-encryption

ActiveLibrary[Security](/categories/security)

ghalibilal/laravel-hmac-encryption
==================================

A Laravel encryption package with HMAC integrity check

2421PHP

Since Oct 12Pushed 7mo agoCompare

[ Source](https://github.com/Ghalibilal/laravel-hmac-encryption)[ Packagist](https://packagist.org/packages/ghalibilal/laravel-hmac-encryption)[ RSS](/packages/ghalibilal-laravel-hmac-encryption/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

🔐 Laravel Encryption by Hazrat Bilal Ghalib
===========================================

[](#-laravel-encryption-by-hazrat-bilal-ghalib)

A simple and secure Laravel package for encrypting and decrypting model attributes, queries, and sensitive data using AES-256-CBC with HMAC integrity.

✅ Supports `.env`-based encryption keys and automatic attribute encryption via model casting.

---

📦 Features
----------

[](#-features)

- 🔐 AES-256-CBC encryption with HMAC SHA-256
- 🧠 Automatic encryption/decryption via Eloquent attribute casting
- 🧱 Custom query macros: `whereEncrypted`, `orWhereEncrypted`
- ⚙️ Configurable encryption key and IV from `.env`
- ✅ Facade support for easy usage

---

🚀 Installation
--------------

[](#-installation)

```
composer require ghalibilal/laravel-hmac-encryption:dev-main
```

Then publish the configuration file:

```
php artisan vendor:publish --tag=config
```

🔐 .env Configuration

You must define two secure values in your .env file:

```
ENCRYPTION_KEY=base64:your_base64_encoded_32_byte_key_here
ENCRYPTION_SECRET=base64:your_base64_encoded_16_byte_iv_here
```

🛠 How to generate secure keys

```
Generate a 32-byte encryption key:

php -r "echo 'base64:' . base64_encode(random_bytes(32)) . PHP_EOL;"

Generate a 16-byte IV (initialization vector):

php -r "echo 'base64:' . base64_encode(random_bytes(16)) . PHP_EOL;"
```

⚠️ These values are required and must be securely stored.

🧠 Usage of EncryptedCast in a Model

Automatically encrypt/decrypt specific model fields:

```
use Illuminate\Database\Eloquent\Model;
use Ghalibilal\LaravelEncryption\Casts\EncryptedCast;

class User extends Model
{
    protected $casts = [
        'email' => EncryptedCast::class,
        'phone' => EncryptedCast::class,
    ];
}
```

🔍 Query Using Encrypted Values

```
User::whereEncrypted('email', '=', 'secret@example.com')->first();
User::orWhereEncrypted('phone', '=', '1234567890')->get();
```

🔑 Artisan Commands
------------------

[](#-artisan-commands)

### Encrypt Model Attributes

[](#encrypt-model-attributes)

You can encrypt attributes of a model directly from the terminal using:

```
php artisan encrypt:model --class="App\\Models\\User"
```

The package automatically encrypts the value before executing the query.

```
🧪 Example
use Ghalibilal\LaravelEncryption\Facades\Encryption;

$plain = 'Sensitive info';

$encrypted = Encryption::encrypt($plain);
$decrypted = Encryption::decrypt($encrypted);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance45

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/ghalibilal-laravel-hmac-encryption/health.svg)

```
[![Health](https://phpackages.com/badges/ghalibilal-laravel-hmac-encryption/health.svg)](https://phpackages.com/packages/ghalibilal-laravel-hmac-encryption)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[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

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

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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