PHPackages                             hivelink/encrypt - 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. hivelink/encrypt

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

hivelink/encrypt
================

Auto Encrypt and Decrypt Database through Eloquent With HivelinkTeam

v1.0.3(2y ago)0125↓50%MITPHP

Since Dec 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/hivelinklib/hivelink-encrypt)[ Packagist](https://packagist.org/packages/hivelink/encrypt)[ RSS](/packages/hivelink-encrypt/feed)WikiDiscussions main Synced 1mo ago

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

Hivelink Database Encrypt for Laravel
=====================================

[](#hivelink-database-encrypt-for-laravel)

Package for encrypting and decrypting model attributes for Laravel using openssl
--------------------------------------------------------------------------------

[](#package-for-encrypting-and-decrypting-model-attributes-for-laravel-using-openssl)

Key Features
------------

[](#key-features)

- Encrypt, Decrypt database fields easily
- Minimal configuration
- Include searching encrypted data using the following: `whereEncrypted` and `orWhereEncrypted`
- uses openssl for encrypting and decrypting fields
- auto encrypt or decrypt data with model

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

[](#requirements)

- Laravel: &gt;= 5
- PHP: &gt;= 7.3
- Max Laravel Support =&gt; 10

Schema Requirements
-------------------

[](#schema-requirements)

Encrypted values are usually longer than plain text values, sometimes much longer. You may find that the column widths in your database tables need to be altered to store the encrypted values generated by this package.

We highly recommend to alter your column types to `TEXT` or `LONGTEXT`

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

[](#installation)

### Step 1: Composer

[](#step-1-composer)

Via Composer command line:

```
$ composer require hivelink/encrypt
```

### Step 2: Add ServiceProvider to your app/config.php file (Laravel 5.4 or below)

[](#step-2-add-serviceprovider-to-your-appconfigphp-file-laravel-54-or-below)

Add the service provider to the providers array in the config/app.php config file as follows:

```
    'providers' => [
        ...
        \Hivelink\DBEncryption\Providers\DBEncryptionServiceProvider::class,
    ],
```

Usage
-----

[](#usage)

Use the `EncryptedAttribute` trait in any Eloquent model that you wish to apply encryption to and define a `protected $encrypted` array containing a list of the attributes to encrypt.

For example:

```

    use Hivelink\DBEncryption\Traits\EncryptedAttribute;

    class User extends Eloquent {
        use EncryptedAttribute;

        /**
         * The attributes that should be encrypted on save.
         *
         * @var array
         */
        protected $encryptable = [
            'first_name', 'last_name'
        ];
    }
```

By including the `EncryptedAttribute` trait, the `setAttribute()`, `getAttribute()` and `getAttributeFromArray()`methods provided by Eloquent are overridden to include an additional step.

Encryption and decryption based on each user
--------------------------------------------

[](#encryption-and-decryption-based-on-each-user)

### Step 1: Composer

[](#step-1-composer-1)

Add line in controller :

```
use Hivelink\DBEncryption\Encrypter;
```

Use the `encryptUser` , `decryptUser` r method, you can encrypt and decrypt any information based on the user ID

For example:

```

    Route::get('/', function () {
        $loadLib=new Encrypter();
        $text="Hi my Dear?";
        $userMail/$userPhone="test@hivelink.co";
        $userRecord/OtherData=2342342;
        $encData=$loadLib->encryptUser($text,$userMail,$userRecord);

        $decData=$loadLib->decryptUser($encData,$userMail,$userRecord);

        return $decData
    });
```

With this method, you can even encrypt the duplicate information of users without similarity and store it in the database. This method is to increase the security of information in your project database.

### Searching Encrypted Fields Example:

[](#searching-encrypted-fields-example)

Searching encrypted field can be done by calling the `whereEncrypted` and `orWhereEncrypted` functions similar to laravel eloquent `where` and `orWhere`.

```
    namespace App\Http\Controllers;

    use App\User;
    class UsersController extends Controller {
        public function index(Request $request)
        {
            $user = User::whereEncrypted('first_name','john')
                        ->orWhereEncrypted('last_name','!=','Doe')->firstOrFail();

            return $user;
        }
    }
```

### Encrypt your current data

[](#encrypt-your-current-data)

If you have current data in your database you can encrypt it with the: `php artisan encryptable:encryptModel 'App\User'` command.

Additionally you can decrypt it using the: `php artisan encryptable:decryptModel 'App\User'` command.

Note: You must implement first the `Encryptable` trait and set `$encryptable` attributes

### Exists and Unique Validation Rules

[](#exists-and-unique-validation-rules)

If you are using exists and unique rules with encrypted values replace it with exists\_encrypted and unique\_encrypted `php       $validator = validator(['email'=>'foo@bar.com'], ['email'=>'exists_encrypted:users,email']); $validator = validator(['email'=>'foo@bar.com'], ['email'=>'unique_encrypted:users,email']); `

Frequently Asked Question
-------------------------

[](#frequently-asked-question)

#### Can I search encrypted data?

[](#can-i-search-encrypted-data)

YES! You will able to search on attributes which are encrypted by this package because. If you need to search on data then use the `whereEncrypted` and `orWhereEncrypted` function:

```
    User::whereEncrypted('email','hive@hivelink.co')->orWhereEncrypted('email','link@hivelink.co')->firstOrFail();

```

It will automatically added on the eloquent once the model uses `EncryptedAttribute`

#### Can I encrypt all my `User` model data?

[](#can-i-encrypt-all-my-user-model-data)

Aside from IDs you can encrypt everything you wan't

For example: Logging-in on encrypted email

```
$user = User::whereEncrypted('email','hive@hivelink.co')->filter(function ($item) use ($request) {
        return Hash::check($password, $item->password);
    })->where('active',1)->first();

```

License
-------

[](#license)

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

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Total

2

Last Release

892d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hivelink-encrypt/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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