Architecture Fit The addition of deterministic encryption support in Kunci v1.1 introduces a paradigm shift in how sensitive data (e.g., PII, financial records) is encrypted within Laravel applications. Deterministic encryption ensures identical plaintext inputs produce identical ciphertext outputs, enabling efficient indexing, searching, and deduplication of encrypted data—critical for compliance (e.g., GDPR, HIPAA) and performance-sensitive use cases. This aligns well with systems requiring searchable encryption (e.g., audit logs, user profiles) or data deduplication (e.g., payment gateways, CRM integrations).
Integration Feasibility
Kunci::encryptDeterministic()).Kunci::setDeterministicKey() for granular control.UNIQUE constraints to UNIQUE on ciphertext).Technical Risk
Kunci::deterministic() only for non-searchable data or pair with format-preserving encryption (FPE) for searchability.Key Questions
LIKE on encrypted fields) and their impact on DB indexing?Stack Fit
config, services.php, and Encrypter facade.BINARY/VARBINARY fields (MySQL/PostgreSQL) or JSONB (for nested deterministic encryption).Migration Path
EXPLAIN ANALYZE on encrypted WHERE clauses).user_metadata).config('features.deterministic_encryption') to toggle behavior.Compatibility
email encrypted both ways).Sequencing
.env or Vault:
KUNCI_DETERMINISTIC_KEY=base64-encoded-32-byte-key
KUNCI_DETERMINISTIC_SALT=unique-per-dataset-salt
deterministic flag to encrypted fields or create a shadow table.// Probabilistic (existing)
$ciphertext = Kunci::encrypt('secret');
// Deterministic (new)
$ciphertext = Kunci::deterministic()->encrypt('searchable-secret');
Maintenance
// Example key rotation script
Kunci::setDeterministicKey(newKey());
DB::table('users')->whereNotNull('encrypted_email')->get()->each(fn ($user) =>
User::find($user->id)->forceFill(['encrypted_email' => Kunci::deterministic()->encrypt($user->email)])->save()
);
Support
debug() mode to log encryption metadata.Scaling
CREATE INDEX idx_encrypted_email ON users(encrypted_email)).WHERE encrypted_email LIKE '%@gmail.com').Failure Modes
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Key loss | Permanent data loss for deterministic fields | Backup keys in a secure vault (e.g., HashiCorp Vault). |
| Key exposure | Data breach | Use hardware-backed keys (e.g., AWS CloudHSM). |
| Database corruption (encrypted fields) | Data unreadable | Implement checksum validation for ciphertexts. |
| Schema migration failure | Partial deterministic adoption | Use transactions and rollback scripts. |
| Performance degradation | Slow queries on encrypted fields | Optimize queries (e.g., avoid LIKE on long ciphertexts). |
Ramp-Up
How can I help you explore Laravel packages today?