Download the PHP package vimatech/laravel-secure-fields without Composer

On this page you can find all versions of the php package vimatech/laravel-secure-fields. 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-secure-fields

Laravel Secure Fields

CI Latest Version on Packagist Total Downloads License

Secure encrypted Eloquent model fields for Laravel.

Laravel Secure Fields lets you encrypt sensitive database fields with AES-256-GCM while preserving a natural Eloquent developer experience — searchable, maskable, and rotatable.

Why Laravel Secure Fields?

Most Laravel apps storing sensitive data eventually need to answer:

Laravel Secure Fields provides a focused encryption layer for that.

Feature Matrix

Feature Supported
AES-256-GCM encryption
Random IV per encryption
Auth tag validation
Searchable encrypted fields (blind index)
Key rotation command
Field masking
Encrypted JSON fields
Serialization protection
Audit logging
Facade
LIKE / partial search ❌ (by design)
Homomorphic encryption
UI components

Laravel Secure Fields vs Laravel's Built-in Encryption

Laravel Secure Fields manages:

Laravel's encrypt() / Crypt facade:

They are complementary — this package is purpose-built for Eloquent model fields.

Use Cases

Installation

Requirements

Publish config

Publish migrations (optional, for audit logging)

Generating Keys

Important: Always generate dedicated keys. Never leave SECURE_FIELDS_KEY or SECURE_FIELDS_HASH_KEY empty — an empty value silently falls back to a key derived from APP_KEY, which means a compromised APP_KEY would expose both session/cookie encryption and all field-level ciphertext.

Generate a 32-byte encryption key (base64-encoded):

Generate a 32-byte hash key (hex-encoded or base64):

Add both to your .env:

Minimum requirements:

Quick Start

1. Add encrypted fields to your model

2. Create your migration

Important: Use TEXT columns for encrypted fields — encrypted payloads are larger than plaintext. Add nullable() only when the field is genuinely optional in your domain. The cast handles null values correctly in both cases.

3. Use it naturally

Searchable Encrypted Fields

Search encrypted fields without exposing plaintext:

The package stores a deterministic HMAC-SHA256 hash alongside the encrypted value, enabling exact-match queries while the actual data remains encrypted.

How it works

  1. On save: encrypts the value AND stores HMAC-SHA256(plaintext) in a {field}_hash column
  2. On search: hashes the search term and queries the hash column
  3. The hash is one-way — it cannot be reversed to obtain the plaintext

Search normalization

Blind index hashes are case-insensitive and whitespace-trimmed. These three searches are equivalent and will find the same record:

This normalization is applied consistently on both write and search, so records are always findable regardless of input case.

Field Masking

Encrypted fields are hidden by default from toArray() and toJson() to prevent accidental exposure. toMaskedArray() makes them visible with masking applied:

You can also mask individual fields with custom parameters:

Encrypted JSON Fields

Encrypt entire JSON structures:

Key Rotation

Rotate encryption keys without downtime. The rotation command re-encrypts all field values with the new key while the SECURE_FIELDS_KEY in your .env already points to the new key.

Rotation workflow

  1. Generate a new key: php -r "echo base64_encode(random_bytes(32)), PHP_EOL;"
  2. Update SECURE_FIELDS_KEY in .env to the new key
  3. Run the rotation command with the old key
  4. Verify data integrity
  5. Remove the old key from any backups or records

Running the rotation

The old key is read via a secure interactive prompt that does not appear in process listings or shell history:

Security note: For automated pipelines, prefer passing the old key via an environment variable read inside a wrapper script rather than as a CLI argument:

Hash key rotation

The SECURE_FIELDS_HASH_KEY is separate from the encryption key and used only for HMAC blind indexes. If you need to rotate the hash key:

  1. Changing SECURE_FIELDS_HASH_KEY will invalidate all existing blind indexes — secureWhere() queries will return no results for existing records until indexes are rebuilt.
  2. A secure-fields:rehash command for rebuilding indexes is planned for a future release.
  3. Until then, rotate the hash key only during a maintenance window where you can rebuild indexes manually.

Serialization Protection

Encrypted fields are automatically hidden from toArray() and toJson() to prevent accidental exposure in API responses or logs:

Audit Logging

The package can log every field decryption event, enabling access trail for GDPR, HIPAA, and SOC 2 compliance.

Configuration

What is logged

Event Trigger Recorded fields
decrypt Reading an encrypted attribute model, model_id, field, user_id, action, ip_address, user_agent
key_rotation secure-fields:rotate completes model, records_processed, user_id, action, ip_address, user_agent

Deduplication

Within a single request, the same (model, id, field) combination is logged at most once, regardless of how many times the attribute is accessed. This prevents log flooding when iterating over collections.

Database driver

With SECURE_FIELDS_AUDIT_DRIVER=database, audit rows are batched and written in a single INSERT at the end of the request — not one INSERT per access. This keeps the hot path free of synchronous database writes.

The audit table must be published and migrated before enabling the database driver:

FrankenPHP / Laravel Octane

The AuditLogger is bound as scoped() in the service container, meaning a fresh instance is created for each request in Octane and FrankenPHP worker mode. The deduplication cache and pending batch are request-scoped and never leak between requests.

Log driver

The log driver writes to a Laravel log channel with no additional database queries — a good default for high-throughput applications.

Facade Usage

Configuration

Environment Variables

Complete Example

Security Notes

Encryption

Key Management

Searchable Fields

Best Practices

Philosophy

Laravel Secure Fields is intentionally focused.

The package manages:

Design principles:

It does not aim to become a permissions framework, a full-disk encryption system, or a key management service.

Testing

Run static analysis:

Format code:

Contributing

Contributions are welcome.

Please ensure:

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our Security Policy for reporting vulnerabilities.

License

The MIT License (MIT). Please see License File for more information.

Credits

Built and maintained by Vimatech. Created by Adel Zemzemi.


All versions of laravel-secure-fields with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/encryption Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
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 vimatech/laravel-secure-fields contains the following files

Loading the files please wait ...