Download the PHP package sneakyx/laravel-dynamic-encryption without Composer

On this page you can find all versions of the php package sneakyx/laravel-dynamic-encryption. 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-dynamic-encryption

sneakyx/laravel-dynamic-encryption

A minimalist Laravel package that replaces the default Encrypter with a dynamic key system. The application encryption key is not taken from APP_KEY, but resolved at runtime from a volatile store (cache) and/or derived from a password using a KDF. This enables ephemeral key management and straightforward rotation. Read more in: Why does this exist?

Installation

Local Development (Monorepo)

  1. The package is already located at: packages/only-local/laravel-dynamic-encryption
  2. Update autoloading:

Standalone Project (Packagist/GitHub)

The package uses Laravel’s auto-discovery and binds the service provider automatically.

Configuration

Add environment variables and publish/adjust the config if needed.

Relevant .env variables (examples):

See config/dynamic-encryption.php for all options.

Key size is taken from config('app.cipher'):

Key material: two supported formats

Behavior when the key bundle is missing

Usage

The package replaces Laravel’s default Encrypter. Use the Crypt facade as usual:

Usage

Use the EncryptedNullableCast or EncryptedNullableJsonCast in your model's $casts array:

Migration from v0.3.x

Replace the DynamicEncryptable trait and $encryptable property with casts:

Please migrate to the Cast-based approach above. The trait will log deprecation warnings.

Cast-based "Locked" Flow

Instead of using a cryptographic fallback (e.g., APP_KEY), the following cast returns a LockedEncryptedValue placeholder object when the key is missing—no exception is thrown. This allows the UI to display an "unlock" dialog without breaking the rendering flow. If you have also (legacy) unencrypted fields for some entities, you also can use the .env value:

(There are also the values null and fail for the policy.)

1) Use Cast:

2) Check in the UI:

3) When saving:

Note: LockedEncryptedValue is string-/JSON-serializable (returns an empty string or null) and contains no plaintext data.

Where is the key/password stored?

The package expects a key bundle (array) in your cache under DYNAMIC_ENCRYPTION_CACHE_KEY. Read more: Where is the key?

Data Prefixing (Versioned Encryption)

Starting with version 0.2.0, encrypted values are stored with a versioned prefix (default: dynenc:v1:). This allows the system to reliably distinguish between:

  1. Encrypted ciphertext: Values starting with the prefix.
  2. Legacy plaintext: Values without the prefix (e.g., from before the encryption was enabled).

Why use a prefix?

Without a prefix, it's difficult to know if a string in the database is already encrypted or if it's still plaintext. Attempting to decrypt plaintext usually results in a decryption error. With the prefix, the EncryptedNullableCast can safely return the raw value if no prefix is found, preventing errors during migration or partial rollouts.

Migration Command

If you have data that was encrypted with an older version of this package (without a prefix) or using different encryption parameters, you can use the migrate-legacy command to re-encrypt your data with the current settings:

The command decrypts legacy values (without prefix, encrypted with an old key/salt) and re-encrypts them using the current encrypter and adds the versioned prefix.

By default, it automatically attempts multiple decryption strategies:

Options:

The command only processes values that:

  1. Do not already have the current prefix.
  2. Appear to be encrypted (e.g., valid JSON structure with iv, value, and mac).

But be careful, there is a theoretical possibility that unencrypted Data is misinterpreted.

Decrypt encrypted fields and store plaintext

Use this if you need to permanently decrypt encrypted values in your database for specific models/fields:

Encrypt any still-plaintext values in bulk

Use this when you have legacy plaintext in encryptable fields and want to encrypt them in one go:

Key Rotation

Re-encrypt existing data from an old password to a new one (interactive):

Options:

How it works (since v0.5.1):

Testing

If you are writing Feature tests for your application, you need to ensure that a valid encryption key is present in the cache. Otherwise, models using DynamicEncryptable might throw exceptions or fail to save.

This package ships with a helper trait DynamicEncryptionTestLoader. Use it in your base TestCase to automatically inject a temporary key into the cache for the duration of the tests.

Security notes

Compatibility

Tested with Laravel 10.

License

MIT


All versions of laravel-dynamic-encryption with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/encryption Version ^10.0|^11.0|^12.0
illuminate/cache Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.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 sneakyx/laravel-dynamic-encryption contains the following files

Loading the files please wait ...