-
Notifications
You must be signed in to change notification settings - Fork 0
add encrypted fields doc & images #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mohammedbashir
wants to merge
1
commit into
master
Choose a base branch
from
ext/encrypted-fields
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+98.4 KB
docs/_static/images/espocrm-extensions/encrypted-fields/add-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
docs/_static/images/espocrm-extensions/encrypted-fields/encrypted-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Encrypted Fields Extension | ||
|
|
||
| ## Overview | ||
| The **Encrypted Fields** extension adds a new field type `encrypted` to EspoCRM. This allows you to securely store sensitive information (such as API keys, secrets, or personal identification numbers) in the database using reversible encryption. | ||
|
|
||
| Unlike the standard `password` field which uses one-way hashing, the `encrypted` field allows the system to decrypt and retrieve the original value when needed (e.g., for integrations or processing), while keeping it secure in the database. | ||
|
|
||
| ## Features | ||
| * **AES-256-CBC Encryption**: Uses industry-standard strong encryption. | ||
| * **Automatic Key Management**: Automatically generates a secure 256-bit encryption key (`extendedEncryptionKey`) upon first use if not already present. | ||
| * **Unique IV per Value**: Generates a random Initialization Vector (IV) for every record to ensure that identical values produce different encrypted strings. | ||
| * **Secure Storage**: The encrypted value and its IV are stored in separate columns in the database. | ||
| * **UI Security**: Fields behave like password fields in the user interface (masked input, masked display), preventing casual viewing of sensitive data. | ||
|
|
||
|  | ||
|
|
||
| ## Configuration | ||
| The extension uses a global encryption key stored in your EspoCRM configuration. | ||
|
|
||
| 1. **Key Generation**: The first time you save a record with an encrypted field, the extension checks for `extendedEncryptionKey` in your configuration. If missing, it generates a secure 32-byte hex key and saves it to `data/config.php`. | ||
| 2. **Manual Configuration**: You can optionally define the key manually in `data/config.php`: | ||
| ```php | ||
| 'extendedEncryptionKey' => 'YOUR_32_BYTE_HEX_KEY', | ||
|
eymen-elkum marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| > **Warning**: Do not lose this key! If the `extendedEncryptionKey` is lost or changed, all previously encrypted data will become unreadable. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Adding an Encrypted Field | ||
| 1. Go to **Administration > Entity Manager**. | ||
| 2. Select the entity where you want to add the field. | ||
| 3. Click **Fields** and then **Add Field**. | ||
| 4. Select **Encrypted** from the Type dropdown. | ||
| 5. Configure the field label and name, then click **Save**. | ||
|
|
||
|  | ||
|
|
||
| ### Developer Usage | ||
| To decrypt values programmatically (e.g., in a custom hook or service), use the `DecryptUtil` class provided by the extension. | ||
|
|
||
| ```php | ||
| use Espo\Modules\EncryptedFields\Utils\DecryptUtil; | ||
|
|
||
| // ... inside your class method where $entity and $config are available | ||
|
|
||
| $fieldName = 'mySecretField'; | ||
| $encryptedValue = $entity->get($fieldName); | ||
| $iv = $entity->get($fieldName . 'Iv'); // The IV is stored in a field with 'Iv' suffix | ||
|
|
||
| // Decrypt the value | ||
| $decryptedValue = DecryptUtil::from($encryptedValue, $iv, $config); | ||
|
|
||
| if ($decryptedValue !== false) { | ||
| // Use the decrypted value | ||
| } | ||
| ``` | ||
|
|
||
| ## Database Structure | ||
| For a field named `bank_account_number`, the extension creates: | ||
| * `bank_account_number`: Stores the encrypted string (ciphertext). | ||
| * `bank_account_number_iv`: Stores the base64-encoded Initialization Vector. | ||
|
eymen-elkum marked this conversation as resolved.
|
||
|
|
||
| Both columns are required to decrypt the data. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other EspoCRM extension docs in this repo appear to start with YAML front-matter (e.g.,
icon,title,description) that the docs site likely uses for navigation/metadata. This page currently starts directly with a#header, so it may not render consistently or be missing metadata; consider adding the same front-matter block at the top (see e.g.docs/espocrm-extensions/mask-field/index.mdlines 1-5).