Download the PHP package ginkelsoft/laravel-encrypted-search-index without Composer

On this page you can find all versions of the php package ginkelsoft/laravel-encrypted-search-index. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-encrypted-search-index

Ginkelsoft Laravel Encrypted Search Index

Tests Latest Version on Packagist Total Downloads Laravel PHP

Overview

Modern applications that handle sensitive user data—such as healthcare, financial, or membership systems—must ensure that all personally identifiable information (PII) is properly encrypted at rest. However, standard encryption creates a practical challenge: once data is encrypted, it can no longer be searched efficiently.

Laravel's built-in Crypt system offers strong encryption (AES-256-CBC) but provides no mechanism for searching encrypted values. Some systems attempt to address this by storing partial plaintext or using blind indexes, which can leak statistical patterns and increase the risk of correlation attacks.

The Laravel Encrypted Search Index package provides a clean, secure, and scalable alternative. It allows encrypted model fields to be searched using deterministic hashed tokens, without ever exposing plaintext data.


Problem Statement

The traditional trade-off

When data is fully encrypted, you lose the ability to perform meaningful queries. Developers must choose between:

  1. Strong security (no search): Encrypt every value with a random IV; searches become impossible.
  2. Weak security (searchable): Store hashed or partially-encrypted values that can be compared, leaking patterns.

This package removes that trade-off by introducing a detached searchable index that maps encrypted records to deterministic tokens.


Key Features

How It Works

Each model can declare specific fields as searchable. When the model is saved, the system normalizes the field value, generates one or more hashed tokens, and stores them in a separate table named encrypted_search_index or in an Elasticsearch index if configured.

When you search, the package hashes your input using the same process and retrieves matching model IDs from the index.

1. Token Generation

For each configured field:

Tokens are scoped per model and field — the same value in User.email and Client.email produces different tokens, preventing cross-model correlation.

2. Token Storage

By default, all tokens are stored in the database table encrypted_search_index. When Elasticsearch is enabled, they are stored in the configured Elasticsearch index instead.

Example structure:

model_type model_id field type token
App\Models\Client 42 last_names exact [hash]
App\Models\Client 42 last_names prefix [hash]

3. Querying

The package provides two Eloquent scopes:

These use indexed lookups (DB or Elasticsearch) and remain performant even at scale.


Elasticsearch Integration

Enabling Elasticsearch

To enable Elasticsearch as the storage and query backend for encrypted tokens, set the following in your .env file:

See the Configuration section for the full config/encrypted-search.php reference, including authentication and result limits.

When enabled, the package will skip database writes to encrypted_search_index and instead sync tokens directly to Elasticsearch via the ElasticsearchService.

Searching via Elasticsearch

To manually query Elasticsearch for a specific token:

Both the database and Elasticsearch drivers use the same search scopes — your application code remains identical regardless of which backend is active.

For prefix-based queries, you can match multiple tokens:

The same token-based hashing rules apply — plaintext values must first be converted into deterministic tokens.


Security Model

Threat Mitigation
Database dump or breach Tokens cannot be reversed (SHA-256 with pepper and context salt).
Cross-model correlation Tokens are scoped per model and field; same value produces different tokens across models.
Insider access No sensitive data in index table; encrypted fields remain opaque.
Leaked APP_KEY Irrelevant for tokens; pepper is stored separately in .env.

This design follows a defense-in-depth model: encrypted data stays secure, while search operations remain practical.


Installation

If you plan to use the Elasticsearch integration, make sure an Elasticsearch instance (version 8.x or newer) is running and accessible at the host defined in your .env file.

Then add a unique pepper to your .env file:


Configuration

config/encrypted-search.php:

Configuration Options

Option Default Description
search_pepper '' Secret pepper value for token hashing. Required for security.
max_prefix_depth 6 Maximum number of prefix characters to index (e.g., "wietse" → w, wi, wie, wiet, wiets, wietse)
min_prefix_length 3 Minimum search term length for prefix queries. Prevents overly broad matches from short terms like "w" or "de".
auto_index_encrypted_casts true Automatically index fields with encrypted cast types
elasticsearch.enabled false Use Elasticsearch instead of database for token storage
elasticsearch.host http://elasticsearch:9200 Elasticsearch host URL
elasticsearch.index encrypted_search Elasticsearch index name
elasticsearch.max_results 10000 Maximum number of results returned from Elasticsearch queries
elasticsearch.auth.type null Authentication type: basic, api_key, bearer, or null for none
debug false Enable debug logging for index operations

Minimum Prefix Length

The min_prefix_length setting prevents performance issues and false positives from very short search terms.

Example with min_prefix_length = 3 (default):

Recommended values:

To adjust this setting, add to your .env:


Usage

Model Setup

If auto_index_encrypted_casts is enabled in the configuration (default: true), all model fields that use an encrypted: cast will be automatically indexed for exact search, even if they are not explicitly listed in $encryptedSearch.

You can also use PHP attributes to control search behavior per field:

When a record is saved, searchable tokens are automatically generated in encrypted_search_index or synced to Elasticsearch.

Searching

Single Field Search

Multi-Field Search

Search across multiple fields simultaneously using OR logic:

Use cases for multi-field search:

Note: Multi-field searches automatically deduplicate results, so if a record matches in multiple fields, it will only appear once in the results.

Attributes always override global or $encryptedSearch configuration for the same field.


Rebuilding or Syncing the Search Index

This command automatically detects whether you are using the database or Elasticsearch driver, and rebuilds the appropriate index accordingly.

Rebuild indexes via Artisan:

If Elasticsearch is enabled, this will repopulate the Elasticsearch index instead of the database.


Scalability and Performance

The detached index structure scales linearly and supports millions of records efficiently.


Framework Compatibility

Laravel Version Supported PHP Versions
10.x 8.2 – 8.3
11.x 8.2 – 8.4
12.x 8.3 – 8.5
13.x 8.4 – 8.5

The package is continuously tested across all supported combinations using GitHub Actions.

Supported Databases

The package is database-agnostic and works with any database supported by Laravel:

Database Status
MySQL / MariaDB Fully supported
PostgreSQL Fully supported
SQLite Fully supported (used in CI tests)
SQL Server Supported

Alternatively, Elasticsearch can be used as a dedicated search backend instead of the database.


Compliance


Troubleshooting

ConnectionException (cURL error 7)
Ensure your Elasticsearch container or service is running and reachable at the configured ELASTICSEARCH_HOST.

Missing index mappings
If you haven’t created the Elasticsearch index yet, initialize it manually:


License

MIT License (c) 2026 Ginkelsoft


All versions of laravel-encrypted-search-index with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/support Version ^10.0 || ^11.0 || ^12.0 || ^13.0
ext-intl Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ginkelsoft/laravel-encrypted-search-index contains the following files

Loading the files please wait ...