docs/docs/en/data-sources/field-encryption/index.md
Sensitive business data, such as customer phone numbers, email addresses, and card numbers, can be encrypted and stored in the database as ciphertext.
:::warning Note
The plugin generates an application key automatically. The key is stored in /storage/apps/main/encryption-field-keys.
An application-key file uses the key ID as its file name and has the .key extension. Do not change the file name.
Keep application-key files safe. If an application-key file is lost, encrypted data cannot be decrypted.
When the plugin is enabled for a sub-application, the default key directory is /storage/apps/${sub-application-name}/encryption-field-keys.
:::
The plugin uses envelope encryption.
options field of the fields table.options field of the fields table...To specify an application key, use the ENCRYPTION_FIELD_KEY_PATH environment variable. The plugin loads the file at this path as the application key.
Application-key file requirements:
.key.ENCRYPTION_FIELD_KEY_PATH=/path/to/my/app-keys/270263524860909922913.key
Encrypted fields support only equals, does not equal, exists, and does not exist filters.
Data is filtered as follows:
. to the signed lookup text and perform a prefix-match lookup against the encrypted database value.:::warning Note
Before using nocobase key-rotation, confirm that the application has loaded this plugin.
:::
After an application is migrated to a new environment, use nocobase key-rotation when you do not want to continue using the old environment's application key.
Key rotation requires the old application's application key. The command generates a new application key, replaces the old key, and saves the new key Base64 encoded in the default storage directory.
# --key-path specifies the old application-key file corresponding to encrypted database data
yarn nocobase key-rotation --key-path /path/to/old-app-keys/270263524860909922913.key
To replace a sub-application application key, add --app-name and specify the sub-application name.
yarn nocobase key-rotation --app-name a_w0r211vv0az --key-path /path/to/old-app-keys/270263524860909922913.key