Field Crypto v1
fieldCrypto is the field-level crypto layer shared across @k-msg/core, @k-msg/messaging, and @k-msg/webhook.
Question this page answers: What are the technical policies operators must know for fieldCrypto?
If terms are unfamiliar, start with Security Glossary and Security Recipes.
Supported modes
Section titled “Supported modes”plain: store as plaintext (discouraged in secure environments)encrypt: encrypted storageencrypt+hash: encrypted storage + hash for lookupmask: masked value storage
Default security behavior
Section titled “Default security behavior”- Once enabled, consumers get
secure default. failModedefaults toclosed.openFallback: "plaintext"is rejected unlessunsafeAllowPlaintextStorage: trueis explicitly set.- Envelope format is JSON text:
{ v, alg, kid, iv, tag, ct }. - Encoding is standardized to
base64urlacross SQL dialects.
Lookup and indexing
Section titled “Lookup and indexing”- Phone lookup does not rely on deterministic encryption.
- Use hash indexes such as
to_hashandfrom_hash. - Hashing uses
HMAC-SHA256(normalizedValue).
AAD and key rotation
Section titled “AAD and key rotation”- Default AAD:
messageId,providerId,tableName,fieldPath(plus optionaltenantId) - Rotation strategy:
active kidfor encrypt,multi-kidfallback for decrypt
Operational metrics
Section titled “Operational metrics”crypto_encrypt_mscrypto_decrypt_mscrypto_fail_countkey_kid_usage
Incident handling hints
Section titled “Incident handling hints”crypto_fail_countspike: verify keys, env vars, and payload shapekidmismatch: verify keyResolver and active key rollout status- backfill interruption: replay migration order (
add columns -> index -> backfill -> optional legacy drop)
Further details: