Data protection: encryption, tokenization and masking
Sensitive data (card numbers, national identifiers, health records, account details, personal information) needs protecting wherever it is: stored, moving between systems, in logs, in test environments and in analytics. Three techniques do most of the work, and they protect against different things.
- Encryption transforms data so only holders of a key can read it.
- Tokenization replaces a sensitive value with a meaningless token, keeping the real value in a separate, tightly controlled vault.
- Masking hides all or part of a value from people who don’t need to see it, either when it’s displayed or by permanently replacing it in copies.
The first decision comes before any of them: don’t collect or keep data you don’t need. Data you don’t hold can’t leak.
Diagram
Section titled “Diagram”- The card number goes straight to the tokenization service.
- The service stores it in its vault and returns a token, which the orders system stores.
- Other systems and analytics see only tokens or masked values.
- Only the payment step, with strict authorization, exchanges the token for the real number.
Choosing a technique
Section titled “Choosing a technique”| Aspect | Encryption | Tokenization | Masking |
|---|---|---|---|
| What it does | Makes data unreadable without a key | Replaces data with a token; the original is kept in a vault | Hides some or all of the value |
| Reversible? | Yes, with the key | Yes, through the vault, for authorized callers | Display masking: the original still exists. Static masking: no |
| Protects against | Stolen disks, backups, intercepted traffic, a breached storage layer | Breach of any system that holds only tokens | People seeing data they don’t need; real data in test |
| Typical uses | Everything at rest and in transit, by default | Card numbers, national IDs, account numbers | Support screens (last four digits), test and analytics copies |
| Main risk | Key management; data is readable to any process with access | The vault becomes the high-value target | Weak masking that can be reversed by joining with other data |
Encryption
Section titled “Encryption”- In transit: TLS everywhere, including inside the network. Mutual TLS between services where identity matters.
- At rest: storage and database encryption, usually on by default in cloud services. It protects against stolen media and some storage-layer breaches, but not against anyone who can query the database, because the database decrypts for them.
- Application-level (field-level) encryption: encrypt specific sensitive fields before they reach the database, so database administrators, backups and SQL injection see only ciphertext.
- Key management: keys in a KMS or HSM, never alongside the data. Use envelope encryption (data keys encrypted by a master key), rotate keys, separate who manages keys from who manages data, and log every key use. Customer-managed keys let you revoke access by disabling a key.
Tokenization
Section titled “Tokenization”Removing real values from most systems shrinks what must be protected and audited. For card data, it’s the main way to reduce the systems in scope for PCI DSS (opens in a new tab). Tokens can preserve format (same length, last four digits) so existing systems and reports keep working. Protect the vault heavily, and audit every detokenization.
Masking
Section titled “Masking”- Dynamic (display) masking: the database or application shows
•••• 4242to users without permission to see the full value. The data itself is unchanged. - Static masking: copies for test, development or analytics have sensitive values permanently replaced with realistic fakes. Production personal data shouldn’t be in test environments at all.
- Beware re-identification. Removing names while keeping birth date, postcode and gender can still identify people. Consider aggregation, generalization or synthetic data for analytics.
Common pitfalls
Section titled “Common pitfalls”- Assuming storage encryption protects against application-level breaches. It doesn’t.
- Keys stored next to the data, or in the application config.
- Sensitive data in logs, which are copied widely and kept for a long time.
- Production copies in test environments “just this once”.
- No data inventory, so nobody knows where sensitive data lives to protect it.
Related patterns
Section titled “Related patterns”Further reading
Section titled “Further reading”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.