PHPackages                             wazza/laravel-db-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. [Database &amp; ORM](/categories/database)
4. /
5. wazza/laravel-db-encryption

ActiveLibrary[Database &amp; ORM](/categories/database)

wazza/laravel-db-encryption
===========================

Production-ready Laravel package for secure, transparent encryption of sensitive model attributes with searchable hash indexes and key rotation support.

v1.0.0(3mo ago)202MITPHPPHP ^8.2 || ^8.3CI passing

Since Jun 13Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/wazzac/laravel-db-encryption)[ Packagist](https://packagist.org/packages/wazza/laravel-db-encryption)[ Docs](https://www.wazzac.dev)[ RSS](/packages/wazza-laravel-db-encryption/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (4)Used By (0)

 [![GitHub Actions](https://github.com/wazzac/laravel-db-encryption/workflows/Tests/badge.svg)](https://github.com/wazzac/laravel-db-encryption/actions) [![GitHub issues](https://camo.githubusercontent.com/d87aefd4691c7fd85d8364c97f631392275e6b520608ef60a5ce865803e75614/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f77617a7a61632f6c61726176656c2d64622d656e6372797074696f6e)](https://github.com/wazzac/laravel-db-encryption/issues) [![GitHub stars](https://camo.githubusercontent.com/69bcf67064ac4458a89c5801b62185cd557d2d7e72f514a166edfd4126bb65e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f77617a7a61632f6c61726176656c2d64622d656e6372797074696f6e)](https://github.com/wazzac/laravel-db-encryption/stargazers) [![GitHub license](https://camo.githubusercontent.com/c42dd734267536832e775a66e69de2ef7f09888fa87a20dbe002fb566895523e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77617a7a61632f6c61726176656c2d64622d656e6372797074696f6e)](https://github.com/wazzac/laravel-db-encryption/blob/main/LICENSE) [![GitHub version](https://camo.githubusercontent.com/b2aef052fd4d65f6746747a23bb86119c8b06fdf88c42d0b3972cd1391d077b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f77617a7a61632f6c61726176656c2d64622d656e6372797074696f6e3f6c6162656c3d76657273696f6e26736f72743d73656d766572)](https://github.com/wazzac/laravel-db-encryption) [![Buy me a coffee](https://camo.githubusercontent.com/24e8d6edab584bb208ad9b37c3c918ab581f5ff86646baba835d9b1663d0802a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532306d6525323061253230636f666665652de298952d79656c6c6f773f7374796c653d666c6174266c6f676f3d6275792d6d652d612d636f66666565266c6f676f436f6c6f723d7768697465)](https://coff.ee/wazzac)

Laravel DB Encryption
=====================

[](#laravel-db-encryption)

A production-ready Laravel package for **secure, transparent encryption** of sensitive model attributes. Store encrypted data in a dedicated table while keeping your main tables clean and performant.

🔐 Why This Package?
-------------------

[](#-why-this-package)

- **Transparent Encryption**: Automatic encryption/decryption via Eloquent trait
- **Separate Storage**: Encrypted data stored in dedicated `encrypted_attributes` table
- **Searchable**: Filter encrypted data using SHA-256 hash indexes
- **Zero Configuration**: Works out of the box with sensible defaults
- **Production Ready**: Comprehensive error handling, logging, and security features
- **Performance**: Batch operations and optimized queries
- **Compliance Ready**: Helps meet GDPR, HIPAA, PCI DSS requirements

📋 Requirements
--------------

[](#-requirements)

- **PHP**: 8.2 or higher
- **Laravel**: 12.x
- **OpenSSL**: PHP OpenSSL extension

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

[](#-installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require wazza/laravel-db-encryption
```

### 2. Publish Configuration &amp; Migrations

[](#2-publish-configuration--migrations)

```
# Publish config file
php artisan vendor:publish --provider="Wazza\DbEncrypt\Providers\DbEncryptServiceProvider" --tag="db-encrypt-config"

# Publish migrations
php artisan vendor:publish --provider="Wazza\DbEncrypt\Providers\DbEncryptServiceProvider" --tag="db-encrypt-migrations"
```

### 3. Generate Encryption Key

[](#3-generate-encryption-key)

```
php artisan db-encrypt:generate-key
```

This adds `DB_ENCRYPT_KEY` to your `.env` file.

### 4. Run Migrations

[](#4-run-migrations)

```
php artisan migrate
```

📖 Usage
-------

[](#-usage)

### Basic Setup

[](#basic-setup)

Add the `HasEncryptedAttributes` trait to your model and define which attributes should be encrypted:

```
