Encrypted columns
The values of a custom column can be kept encrypted in the database. The screens, CSV export, the API and MCP show them masked (like ****8765). Only a person with the permission sees the real value, by pressing the "Show" button.
Use it for values that only some people should see, such as phone numbers, bank account numbers or ID numbers.
Note: this feature is available in Exment v7.3.0 and later.
What it does and does not do
| Encrypted column | |
|---|---|
| Column types | One-line text, multi-line text, email, URL |
| Value on the screens (list, details) | Masked (****8765). A person with the permission gets the "Show" button |
| CSV / Excel export | Masked |
| API / MCP | Masked |
| Search, sort, totals | Not available (partial search, sort, totals, charts, calculations, full-text search) |
| Options it cannot be used with | Search index, unique, multiple selection |
| Editing in the list | Not available (edit it on the data form) |
First: make a key
The key is not APP_KEY. It is kept in DATA_ENCRYPTION_KEYS in .env, never in the database.
- Run this on the server. It prints a new key (it does not write .env).
php artisan exment:data-key generate- Put it in
DATA_ENCRYPTION_KEYSin .env.
DATA_ENCRYPTION_KEYS="k1:(the key printed)"- Keep a copy of the key in a safe place away from the server. If the key is lost, the encrypted values can never be read again.
The keys can also be kept in AWS KMS, AWS Secrets Manager or Vault (EXMENT_DATA_KEY_PROVIDER). See the comments in config/exment.php.
Turn the feature on
- As a system administrator, open Feature Management.
- Turn on "Use" for "Encrypted columns" (key
encrypted_columns), and press [Save].
Encrypt a column
- In the custom column settings, open the column (or make a new one).
- Set "Store encrypted" to YES.
- Choose "Characters shown when masked" (0 to 4, 4 at first). With 4, the last 4 characters are shown, like
****8765. With 0, only****. A short value (not longer than twice that number) is masked whole. - Press [Save].
The permission "Show encrypted values"
To see the real value, a person needs the permission "Show encrypted values" (custom_value_reveal) of a role group. It is in the table permissions and the master permissions (shown while "Encrypted columns" is on in Feature Management).
- A person with the permission gets the "Show" button (the eye icon) next to the masked value. Pressing it shows the real value for a while (30 seconds at first,
EXMENT_ENCRYPTED_REVEAL_SECONDS), then it is masked again. - The person also needs permission to read the data.
- Each press is recorded in the data access log as "Encrypted value shown" (Logs).
- System administrators can always see it.
- With the API,
GET (Exment URL)/admin/api/data/(table name)/(id)/reveal/(column name)gives the real value (the same permission and the API scopevalue_readorvalue_writeare needed). This is recorded too.
Entering data and importing CSV
- On the data form, the box of an encrypted column is empty (the masked value is shown in light text). Saving with the box empty keeps the value. Enter the whole new value only when you change it.
- Entering the masked value (such as
****8765) does not change the value. Importing an exported CSV as it is does not remove the values of encrypted columns. - A masked value that is not the current one (for example
****1111) is refused as an error.
Search, sort and lists
The database has only the encrypted text, so an encrypted column cannot be used for:
- Search (partial search, view filters, full-text search). The values of encrypted columns are not sent to the full-text search server (Meilisearch).
- Sort, totals, charts, calculations
Lists show the masked value, and the column cannot be edited in the list.
A plugin or a script that reads the data gets the real value.
Turning encryption on or off later
- When "Store encrypted" is set to YES on a column that has values, the values are encrypted in the background (the queue). Setting it to NO converts them back. The values in the change history are converted in the same way.
- The values are read normally while they are converted.
- Without a queue worker, they are converted when the column is saved. For a large table, this command on the server is better:
php artisan exment:encrypt-column (table name) (column name)- Turning "Encrypted columns" off in Feature Management does not change columns already encrypted (they are read, and encrypted when saved). To convert one back, set its "Store encrypted" to NO.
Keys, backup and restore
- A backup keeps
APP_KEYand theEXMENT_settings of .env, but notDATA_ENCRYPTION_KEYS. A backup alone cannot read the encrypted columns. - When you restore (also to another server), put the same
DATA_ENCRYPTION_KEYSin .env. Without it, encrypted columns show "(cannot be read: no key)". - Changing
APP_KEYdoes not affect the encrypted columns (other encrypted settings need to be set again). - To change the key:
- Make a new key with
php artisan exment:data-key generateand put it first inDATA_ENCRYPTION_KEYS(keep the old one after it). Example:DATA_ENCRYPTION_KEYS="k2:(new key),k1:(old key)" - Run
php artisan exment:data-key rotateto encrypt the values of the old key again with the new one. - Check with
php artisan exment:data-key statusthat no value uses the old key, then remove the old key.
- Make a new key with
Parameters of notifications and documents
${file:column name}works only for the attachments of "File" and "Image" columns. Any other column (encrypted ones too) gives an empty value (Parameters).
Common problems
- "Store encrypted" is not shown: check that "Encrypted columns" is on in Feature Management, and that the column type is one-line text, multi-line text, email or URL.
- Saving fails with "There is no encryption key": do "First: make a key" above.
- A value shows "(cannot be read now: the key service is not reached)": the keys are kept in a service such as AWS KMS, and it cannot be reached. Values of encrypted columns cannot be saved until it can.
