Skip to content

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.

Tokenization keeps sensitive values in one place1. The card number goes straight to the tokenization service. 2. The service stores it in its vault and returns a token, which the orders system stores. 3. Other systems and analytics see only tokens or masked values. 4. Only the payment step, with strict authorization, exchanges the token for the real number. Checkoutcard entered Tokenization servicevault, strict access Orders databasestores tokens only Payment processingdetokenizes to charge Analyticstokens or masked values1token234
Tokenization keeps sensitive values in one place Only the token vault holds real card numbers. Every other system stores tokens, which are useless if stolen.
  1. The card number goes straight to the tokenization service.
  2. The service stores it in its vault and returns a token, which the orders system stores.
  3. Other systems and analytics see only tokens or masked values.
  4. Only the payment step, with strict authorization, exchanges the token for the real number.
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
  • 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.

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.

  • Dynamic (display) masking: the database or application shows •••• 4242 to 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.
  • 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.

Written and edited by Abhinav Taduka, enterprise software architect.