caeligo/field-encryption-bundle
This document covers all console commands provided by the FieldEncryptionBundle.
Generate a cryptographically secure encryption key.
php bin/console field-encryption:generate-key
| Option | Description |
|---|---|
--env-format |
Output in .env format (FIELD_ENCRYPTION_KEY=...) |
--append-to-env |
Append the key to .env.local file |
# Display a new key
php bin/console field-encryption:generate-key
# Output: a1b2c3d4e5f6...
# Output in .env format
php bin/console field-encryption:generate-key --env-format
# Output: FIELD_ENCRYPTION_KEY=a1b2c3d4e5f6...
# Append to .env.local file
php bin/console field-encryption:generate-key --append-to-env
# Appends: FIELD_ENCRYPTION_KEY=a1b2c3d4e5f6... to .env.local
.env.local or environment variablesRotate encryption keys across all encrypted data. Use this when you need to replace your encryption key.
php bin/console field-encryption:rotate-keys
| Option | Description |
|---|---|
--wizard |
Interactive wizard mode (recommended) |
--dry-run |
Show what would be rotated without making changes |
--entity=CLASS |
Rotate only a specific entity class |
--batch-size=N |
Number of entities per batch (default: 50) |
--continue |
Continue a previously interrupted rotation |
# Interactive wizard (recommended for first-time use)
php bin/console field-encryption:rotate-keys --wizard
# Dry run to preview changes
php bin/console field-encryption:rotate-keys --dry-run
# Rotate specific entity only
php bin/console field-encryption:rotate-keys --entity="App\Entity\Document"
# Continue interrupted rotation
php bin/console field-encryption:rotate-keys --continue
# Custom batch size for memory optimization
php bin/console field-encryption:rotate-keys --batch-size=100
The --wizard flag provides an interactive experience:
Generate a new key:
php bin/console field-encryption:generate-key --env-format
Update configuration:
# config/packages/field_encryption.yaml
field_encryption:
encryption_key: '%env(FIELD_ENCRYPTION_KEY_V2)%' # New key
key_version: 2
previous_keys:
- version: 1
key: '%env(FIELD_ENCRYPTION_KEY_V1)%' # Old key
Run the rotation:
php bin/console field-encryption:rotate-keys --wizard
Rotation progress is saved to var/field_encryption_rotation_progress.json. This allows:
Encrypt data that was stored before encryption was enabled, or migrate unencrypted data to encrypted format.
php bin/console field-encryption:encrypt-existing
| Option | Description |
|---|---|
--dry-run |
Show what would be encrypted without making changes |
--entity=CLASS |
Process only a specific entity class |
--batch-size=N |
Number of entities per batch (default: 50) |
--force |
Skip confirmation prompts |
# Preview what will be encrypted
php bin/console field-encryption:encrypt-existing --dry-run
# Encrypt all unencrypted data
php bin/console field-encryption:encrypt-existing
# Encrypt specific entity
php bin/console field-encryption:encrypt-existing --entity="App\Entity\User"
# Skip confirmation (for automation)
php bin/console field-encryption:encrypt-existing --force
hashField: true| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Configuration error |
| 3 | Interrupted (can be resumed) |
# Key rotation with no prompts
php bin/console field-encryption:rotate-keys --no-interaction --batch-size=100
# Encrypt existing with force flag
php bin/console field-encryption:encrypt-existing --force
# Check if rotation is needed (dry-run returns count)
php bin/console field-encryption:rotate-keys --dry-run 2>&1 | grep "entities need"
Enable logging to track encryption operations:
field_encryption:
logging:
enabled: true
channel: 'security'
level: 'info'
Logs are written to the configured Monolog channel.
How can I help you explore Laravel packages today?