PHPackages                             garethnic/laracrypt - 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. garethnic/laracrypt

ActiveLibrary[Security](/categories/security)

garethnic/laracrypt
===================

Add database encryption to laravel

10[1 issues](https://github.com/garethnic/laracrypt/issues)PHP

Since Mar 16Pushed 10y ago1 watchersCompare

[ Source](https://github.com/garethnic/laracrypt)[ Packagist](https://packagist.org/packages/garethnic/laracrypt)[ RSS](/packages/garethnic-laracrypt/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

LaraCrypt
=========

[](#laracrypt)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f353c3c6338c3d690bd6c7129488ec7b1907f24012df8aa5bbc753f8a6a5e935/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6761726574686e69632f6c61726163727970742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/garethnic/laracrypt)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/00317650d7c21a238fa9689b1aa95d8682fc3610ecda9e9bee74a4a69fd60b81/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6761726574686e69632f6c61726163727970742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/garethnic/laracrypt)

A Laravel package to handle database encryption. In the current state of this project, only symmetric encryption is possible.

Install
-------

[](#install)

Make sure you have [libsodium](https://download.libsodium.org/doc/installation/index.html) installed.

Via Composer

Add the following to your `composer.json` file:

```
"garethnic/laracrypt": "dev-master"

```

Add the garethnic\\ServiceProvider to your config/app.php providers array:

```
garethnic\laracrypt\LaraCryptServiceProvider::class,
```

Then do:

```
$ php artisan vendor:publish
```

To copy the config file over. In this file you can specify where to store and load your key from.

```
'path' => storage_path('keys/encryption.key')
```

**For your database schema make sure the encrypted columns are of type `BLOB`.**

Usage
-----

[](#usage)

You will first need to create your key:

```
$ php artisan laracrypt:key
```

This will generate a key and save it in `storage/keys`. You could also generate the key programmatically via the static `generateKey` method.

In the future more options will be added to make key storage more flexible.

There are multiple ways to go about encrypting/decrypting:

`AppServiceProvider`

```
// Encrypting all attributes
Post::saving(function ($post) {
    foreach($post['attributes'] as $key => $value) {
        $post->$key = LaraCrypt::encrypt($value);
    }
});

// Encrypting all attributes
Post::saving(function ($post) {
    $post->body = LaraCrypt::encrypt($post->body);
});
```

Or in your `Model` you could do:

```
public function setBodyAttribute($value)
{
    $this->attributes['title'] = LaraCrypt::encrypt($value);
}
```

Decrypting:

It's as simple as `LaraCrypt::decrypt($text)`.

In your `Model`:

```
public function getBodyAttribute($value)
{
    return LaraCrypt::decrypt($value);
}
```

TODO
----

[](#todo)

- Add configuration options
- Add support for asymmetric encryption
- Clean up code
- Write tests

Change log
----------

[](#change-log)

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

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

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

License
-------

[](#license)

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

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1523598?v=4)[Gareth](/maintainers/garethnic)[@garethnic](https://github.com/garethnic)

---

Top Contributors

[![garethnic](https://avatars.githubusercontent.com/u/1523598?v=4)](https://github.com/garethnic "garethnic (8 commits)")

### Embed Badge

![Health badge](/badges/garethnic-laracrypt/health.svg)

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

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M141](/packages/mews-purifier)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24820.0k36](/packages/paragonie-ecc)

PHPackages © 2026

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