coka/doctrine-encrypt-bundle
EncryptedString, EncryptedText, EncryptedInteger), which aligns with Laravel applications requiring PII/GDPR-compliant data storage (e.g., passwords, credit cards, health records) or multi-tenant isolation without application-layer encryption.encrypt() helper) is simpler for basic use cases, but this package offers database-level encryption with OpenSSL, reducing application overhead.Model::all()).Model::boot()).ALTER TABLE users MODIFY credit_card VARCHAR(255)), risking downtime in production.config.php).AES-256-CBC by default (vulnerable to padding oracle attacks if not configured with OPENSSL_RAW_DATA).encrypted:array fields).encrypt() helper?
microtime(true).)// app/Models/User.php
use Doctrine\DBAL\Types\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class User extends Model {
protected $casts = [
'credit_card' => 'encrypted_string',
];
public function getAttribute($key) {
if ($key === 'credit_card' && $this->isEncrypted($key)) {
return $this->decryptAttribute($key);
}
return parent::getAttribute($key);
}
}
Str::of($value)->encrypt() (no DBAL overhead).Encryptable trait for models needing encrypted fields.doctrine:query).php artisan doctrine:query "UPDATE users SET credit_card = ENCRYPT(credit_card, 'key')"
encrypt() calls with the bundle’s types.SELECT id, name FROM users).openssl and pdo extensions.encrypt().User::api_token).DB::enableQueryLog()).App\Exceptions\Handler).OpenSSL errors if keys are malformed or missing.try-catch).debug:decrypt Artisan command to test encrypted values.openssl usage in top/htop.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Lost encryption key | Permanent data loss | Backup keys in HSM or KMS. |
| OpenSSL misconfiguration | Data corruption | Use OPENSSL_RAW_DATA flag. |
| Database corruption | Unreadable encrypted fields | Regular backups + CHECKSUM validation. |
| Key rotation failure | Data becomes unreadable | Test rotation in staging first. |
| High query latency | Poor user experience | Cache decrypted data (short TTL). |
RUN docker-php-ext-install openssl).How can I help you explore Laravel packages today?