PHPackages                             novay/kunci-sql - 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. novay/kunci-sql

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

novay/kunci-sql
===============

Seamless encryption for Laravel Eloquent models using Kunci.

1.0(9mo ago)00MITPHPPHP ^8.1

Since Aug 12Pushed 9mo agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

🔑 Kunci-SQL
===========

[](#-kunci-sql)

A Laravel package for automatic database column encryption with support for deterministic encryption to enable searchable encrypted fields. Makes Eloquent models encrypt attributes transparently without manual query changes. It works transparently through your **Eloquent models**.

---

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

[](#key-features)

- **Automatic encryption** when saving encrypted attributes.
- **Automatic decryption** when accessing encrypted attributes.
- Support for **deterministic encryption** (`encryptDeterministic`) on searchable columns for consistent searching.
- Automatic query builder modification to support encrypted searches.
- **Artisan commands** for re-encrypting and re-decrypting encrypted columns.
- Easily integrates with Eloquent models using a trait.

---

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

[](#installation)

Install the package using Composer:

```
composer require novay/kunci-sql
```

After installation, apply the `HasEncryptedAttributes` trait to any model you want to encrypt:

```
use Novay\KunciSql\Traits\HasEncryptedAttributes;

class Todo extends Model
{
    use HasEncryptedAttributes;

    // Define the attributes to be encrypted
    protected array $encrypted = [
        'description' => ['searchable' => true], # Deterministic encryption for searching columns
        'secret_note' # Standard encryption
    ];
}
```

---

Usage
-----

[](#usage)

### Defining encrypted attributes

[](#defining-encrypted-attributes)

Add the `$encrypted` property to your model using the following format:

```
protected array $encrypted = [
    'field_name' => [], # Regular encryption
    'searchable_field' => ['searchable' => true], # Deterministic encryption for searchable columns
];
```

**Note**: Deterministic encryption produces the same ciphertext for the same plaintext. This enables exact-match searching, but it can be a security risk if used on highly sensitive data with low cardinality.

---

### Automatic encryption/decryption

[](#automatic-encryptiondecryption)

- When you save a model, all attributes listed in the `$encrypted` property will be **automatically encrypted**.
- When you access these attributes, they will be **automatically decrypted** before being returned.

---

### Automatic searchable queries with deterministic encryption

[](#automatic-searchable-queries-with-deterministic-encryption)

With deterministic encryption, you can perform searches with a `where` clause as you normally would. Kunci-SQL will encrypt the search value behind the scenes.

Example:

```
// Behind the scenes, the search value will be encrypted deterministically
$results = Todo::where('description', 'Todo 1')->get();
```

If `description` is marked with `searchable => true`, the search will work with deterministic ciphertext matching.

**Important**: Currently, operators like `LIKE` are not supported for searchable columns, as deterministic encryption only works for exact-value matching.

---

### Artisan Commands

[](#artisan-commands)

To manage existing data, you can use the following Artisan commands:

#### Re-encrypt Data

[](#re-encrypt-data)

This command will re-encrypt the data in the specified column.

```
php artisan kunci-sql:re-encrypt {table} {column} [--searchable]
```

Example:

```
# Re-encrypts the 'description' column in the 'todo' table with deterministic encryption
php artisan kunci-sql:re-encrypt todo description --searchable
```

#### Re-decrypt Data

[](#re-decrypt-data)

This command will re-decrypt the data in the specified column.

```
php artisan kunci-sql:re-decrypt {table} {column}
```

---

Configuration
-------------

[](#configuration)

- Use the `--searchable` flag on commands to specify columns using deterministic encryption.
- Ensure your encryption key configuration in `config/kunci-sql.php` is set properly.

---

`HasEncryptedAttributes` Trait
------------------------------

[](#hasencryptedattributes-trait)

This trait is the core of the Kunci-SQL package. It is responsible for:

- `getAttribute($key)` Automatically decrypting values when they are accessed.
- `setAttribute($key, $value)` Automatically encrypting values when they are set.

---

Complete Model Example
----------------------

[](#complete-model-example)

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Novay\KunciSql\Traits\HasEncryptedAttributes;

class Todo extends Model
{
    use HasEncryptedAttributes;

    protected $table = 'todo';

    protected $fillable = ['description', 'done'];

    protected array $encrypted = [
        'description' => ['searchable' => true],
    ];
}
```

---

License
-------

[](#license)

This package is licensed under the **MIT License**.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance58

Moderate activity, may be stable

Popularity0

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

Unknown

Total

1

Last Release

279d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/712577?v=4)[Novianto Rahmadi](/maintainers/novay)[@novay](https://github.com/novay)

---

Top Contributors

[![novay](https://avatars.githubusercontent.com/u/712577?v=4)](https://github.com/novay "novay (1 commits)")

---

Tags

laravelsecurityencryptiondatabaseeloquent

### Embed Badge

![Health badge](/badges/novay-kunci-sql/health.svg)

```
[![Health](https://phpackages.com/badges/novay-kunci-sql/health.svg)](https://phpackages.com/packages/novay-kunci-sql)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[betterapp/laravel-db-encrypter

Provides database model attribute encryption/decryption

365614.7k8](/packages/betterapp-laravel-db-encrypter)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[eusonlito/laravel-database-cache

Cache Database Query results on Laravel Query Builder or Eloquent

194.2k](/packages/eusonlito-laravel-database-cache)

PHPackages © 2026

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