In data masking vs tokenization, the difference is whether the original can come back. Data masking replaces sensitive data with a realistic fake value for good: the copy stays useful for testing, and nobody can get the original back from it. Tokenization replaces sensitive data with a token and keeps the original in a secured token vault, so authorized systems can swap the token back when they need the real value. Encryption scrambles the value with a key, and anyone who holds the decryption key reads the original. One question decides: does anyone downstream need the original value back? If nobody does, mask. If a production system does, tokenize or encrypt.
Data Masking vs Tokenization vs Encryption at a Glance
| Data masking | Tokenization | Encryption | |
|---|---|---|---|
| What replaces the value | A realistic substitute in the same format | A token with no meaning of its own | Ciphertext made with a key |
| Can you get the original back? | No, with static masking | Yes, through the vault, for authorized systems | Yes, for anyone with the key |
| Where the original lives | Nowhere in the masked copy | In the token vault | In the same place, encrypted |
| Format | Kept: names look like names, credit card numbers keep their format | Kept only with format-preserving tokens | Changed, unless you use format-preserving encryption |
| Typical home | Test, development, analytics, vendor copies | Production payment and identity systems | Data at rest, backups, data in transit |
| Main risk | Missed columns and free text | The vault is the prime target | Stolen keys; with TDE, plaintext for every user who can query |
What Data Masking Does
Data masking replaces sensitive information (names, Social Security numbers, emails, credit card numbers, patient data) with realistic data of the same type and format. Tests still pass validation, joins still match, and data breaches in a test environment do not expose real customers, provided no column was missed. There are two kinds:
- Static data masking rewrites a copy of the database. The original data is gone from the copy, so it can go to developers, QA or a vendor.
- Dynamic data masking leaves stored data untouched and masks values in query results or in transit, depending on who reads them. It controls access in production; it does not give you a safe copy.
Techniques are chosen per column: substitution, format-preserving replacement, deterministic replacement so a customer masks the same way in every table, partial masking or nulling. Our guide on how to anonymize a database covers each with SQL.
Data Redaction vs Data Masking
Redaction hides part of a value for display, such as a support screen that shows only the last four digits of a card. Masking produces a full, realistic replacement. A test database full of XXXX-XXXX-XXXX-1234 breaks validation, sorting and every test that needs a real-looking value. In SQL Server, display redaction is a dynamic mask with the partial() function:
ALTER TABLE Sales.Customer
ALTER COLUMN CardNumber
ADD MASKED WITH (
FUNCTION = 'partial(0,"XXXX-XXXX-XXXX-",4)');
Users without the UNMASK permission see the last four digits, and the stored data does not change, as Microsoft's dynamic data masking documentation describes.
What Data Tokenization Does
Tokenization replaces a sensitive value with a token, a surrogate that means nothing on its own, and keeps the mapping between token and original in a token vault. Applications store and pass the token, while access controls on the vault decide who can detokenize. When an authorized system needs the real value, for example in payment processing to charge a card, it sends the token to the tokenization service and gets the original back (detokenization). The PCI Security Standards Council's tokenization guidelines define it this way for card numbers: the primary account number "is replaced with a surrogate value called a token", and de-tokenization is "the reverse process".
So is tokenization reversible? The token alone is not. HashiCorp's Vault tokenization documentation says the original value "cannot be recovered from a token alone" and must be retrieved from the mapping in storage. The system as a whole is reversible for authorized processes, while a stolen token is worthless.
- Vaulted tokenization keeps a mapping table. Every new value is a write, and the vault must stay available, backed up and guarded. The PCI guidelines note that the card data vault "often presents the most attractive target for attackers".
- Vaultless tokenization derives the token from the value with a key, usually through format-preserving encryption. There is no mapping table, but whoever holds the key can reverse every token. Google Cloud Sensitive Data Protection builds such two-way tokens with FPE-FFX or AES-SIV, and one-way tokens with hashing.
- Deterministic or random tokens. By default Vault issues a unique token on every encode. Its convergent mode returns the same token for the same value, which lets you join on tokens but also shows which records share a value.
On compliance, the PCI guidelines say tokenization "may simplify" validation by reducing the number of system components in scope, but solutions "do not eliminate the need to maintain and validate PCI DSS compliance".
Data Masking vs Encryption
Encryption protects data at rest and in transit, but anyone with the key reads it. SQL Server transparent data encryption encrypts data and log files, and its pages "are decrypted when read into memory". Every user who can query the table sees plaintext: TDE protects stolen disks and backups, not data in front of a developer with SELECT rights.
Column encryption narrows who can decrypt, but a test environment then faces a bad choice: hold the key, which makes the copy as sensitive as production, or work with ciphertext that breaks the application. For a test copy, mask.
Data Masking vs Anonymization
Anonymization is an outcome; masking is one way to get there. One-way masking that leaves nothing to trace a person can reach it. Tokenization, keyed hashing and seeded masking keep records linkable for whoever holds the vault, key or salt, so the result is pseudonymous, and GDPR Recital 26 keeps pseudonymised data personal. That settles tokenization vs anonymization too. Treat a masked copy as sensitive data until your privacy team agrees otherwise.
One Card Column, Three Ways: SQL Examples
Take a PostgreSQL customer table with a card_number column. Here is the same column tokenized, encrypted and masked. The vault below is a minimal sketch; in production, tokenization runs on a dedicated service.
1. Tokenize it in production. A vault schema that application roles cannot read, with the card number itself encrypted by pgcrypto, and a column for the token in customer:
CREATE EXTENSION IF NOT EXISTS pgcrypto;
ALTER TABLE customer
ADD COLUMN card_token uuid;
CREATE SCHEMA vault;
REVOKE ALL ON SCHEMA vault FROM PUBLIC;
CREATE TABLE vault.card_token (
token uuid PRIMARY KEY
DEFAULT gen_random_uuid(),
card_enc bytea NOT NULL
);
When a card arrives, store it in the vault and keep only the token in customer.card_token:
INSERT INTO vault.card_token (card_enc)
VALUES (pgp_sym_encrypt(
'4111111111111111', :'vault_key'))
RETURNING token;
Grant the vault to the payment service role only, and detokenize there:
GRANT USAGE ON SCHEMA vault TO payment_svc;
GRANT SELECT ON vault.card_token
TO payment_svc;
SELECT pgp_sym_decrypt(card_enc, :'vault_key')
FROM vault.card_token
WHERE token = :'token';
The key comes from outside the database (a psql variable here). A UUID token does not look like a card number; if a legacy column expects 16 digits, use format-preserving tokens. With HashiCorp Vault's Transform secrets engine, which needs Vault Enterprise with the ADP-Transform module, a format-preserving encryption role does it in one call:
vault write transform/encode/payments \
value=1111-2222-3333-4444
Vault returns a value in the same format, such as 9300-3376-4943-8903, and the decode endpoint reverses it for allowed roles. No mapping table here, so the key is everything. New FPE transformations in Vault 2.2.0 and later use FF1, in line with NIST's SP 800-38G Rev. 1 draft, which removes FF3.
2. Encrypt it. Column encryption with pgcrypto keeps the value in the same row:
ALTER TABLE customer
ADD COLUMN card_enc bytea;
UPDATE customer
SET card_enc = pgp_sym_encrypt(
card_number, :'col_key'),
card_number = NULL;
Any process that holds col_key reads every card number. That is fine for a payment service and wrong for a test environment.
3. Mask it in the test copy. On a restored copy, with the PostgreSQL Anonymizer extension installed and initialized. The first rule covers an untokenized card_number; the second covers a copy of a database that is already tokenized:
SECURITY LABEL FOR anon
ON COLUMN customer.card_number
IS 'MASKED WITH FUNCTION anon.dummy_credit_card_number()';
SECURITY LABEL FOR anon
ON COLUMN customer.card_token
IS 'MASKED WITH VALUE NULL';
DROP SCHEMA vault CASCADE;
SELECT anon.anonymize_database();
A copy of a tokenized database still holds production tokens, and any test service that reaches the production tokenization API can turn them back into card numbers. Null the tokens and keep test networks away from detokenization. In this sketch the vault lives in the same database, so drop it from the copy as well. Then scan free text, where card numbers hide:
SELECT count(*)
FROM support_ticket
WHERE body ~ '\d{4}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}';
A count above zero means card-like numbers are still in the copy: check them before you release it.
Which One to Use: Key Differences by Situation
| Situation | Use | Why |
|---|---|---|
| Test and development databases | Static data masking | Tests need realistic values, not real data |
| Data shared with a vendor or partner | Static data masking | No way back to the original |
| Support screens and reports in production | Dynamic masking or redaction | Stored data stays intact |
| Card numbers that payment systems must use | Tokenization | Only the payment service detokenizes |
| Disks, backups and replicas | Encryption | Protects stolen media |
| Analytics that join records without seeing people | Deterministic tokens or keyed hashing | Joins work; data stays pseudonymous |
Tools for Each Approach
| Tool | Approach | Where it runs |
|---|---|---|
| Datasan by PFLB | Static and dynamic data masking | Inside Oracle, PostgreSQL, SQL Server and MySQL |
| PostgreSQL Anonymizer | Static and dynamic data masking | Inside PostgreSQL, as an extension |
| HashiCorp Vault Transform | Tokenization, format-preserving encryption, masking | Vault Enterprise with ADP-Transform, via API |
| Google Cloud Sensitive Data Protection | Pseudonymization: FPE-FFX, AES-SIV, hashing | Google Cloud, via API |
| SQL Server TDE | Encryption of data and log files at rest | Built into SQL Server and Azure SQL |
| pgcrypto | Column encryption | Inside PostgreSQL, as an extension |
Datasan comes first because most teams asking about masking vs tokenization need production-like test data without the people in it, across several databases with one set of rules. Another tool is the better choice when:
- Production systems need the original value back. Use a tokenization service such as Vault Transform or your payment processor's tokens. Datasan masks; it does not issue tokens.
- You need to protect disks and backups. Use the encryption built into your database engine.
- Your estate is PostgreSQL only and developers write masking rules in SQL: PostgreSQL Anonymizer.
For a longer list of masking products, see our reviews of data masking tools, K2view alternatives and Informatica Cloud Data Masking alternatives.
How Datasan Does It
Datasan is the data masking tool PFLB builds for Oracle, PostgreSQL, SQL Server and MySQL. It covers the static and dynamic masking rows of the decision table:
- Profile. Dictionaries, regex rules and an AI model find personally identifiable information, even in free text.
- Review. Each PII column gets a masking method, and you approve the plan in the UI.
- Mask in place. The Datasan core runs inside the database as a SQL package, with no export to an ETL server. Numbers are re-encoded in a valid format, and the same value is masked the same way in every table, so joins still match.
- Report. Parallel threads process 1,000,000+ table rows per minute, and each run ends with a report of rows processed, errors and values left unmasked.
For live data, Datasan masks on the fly, in transit, by role: the CRM gets full access, analytics gets partial values, and production data stays untouched.
A bank ranked in the top 20 of its market used Datasan to mask a 40 TB Oracle database in 38 hours, as the bank case study shows. PFLB has worked with 300+ companies since 2008 and holds a SOC 2 Type II report.
Need a Helping Hand?
We can do data masking for you. Our engineers build the masking plan, wire it into your environment refresh and check that no real values are left in the copy.
Talk to Our Test Data Engineers
Data Masking vs Tokenization FAQ
Is tokenization the same as encryption?
No. Encryption transforms the value with a key, and anyone with the key reverses it. Vaulted tokenization swaps the value for an unrelated token and keeps the original in a vault, so the token alone reveals nothing. Vaultless tokenization usually relies on format-preserving encryption, so protect its key like the data.
Can masked data be unmasked?
Not after static masking: the originals are not in the copy. Dynamic masking leaves stored data as it was, so users with the right permission see it.
Is tokenized data still personal data?
Yes, under GDPR. Tokenized data is pseudonymized, and Recital 26 keeps pseudonymised data personal because the vault links it back.
Does tokenization take systems out of PCI DSS scope?
It can reduce the number of systems in scope, but you still validate PCI DSS compliance. The tokenization system, vault and key management must run in a PCI DSS compliant environment, and card numbers must not be retrievable from any system you treat as out of scope.
What is the difference between hashing and tokenization?
Hashing is one-way: the same input gives the same hash, and there is no way back. Tokenization keeps a path back for authorized systems. Short values such as SSNs fall to dictionary attacks on plain hashes, so use a secret salt or a keyed hash.
Which is better for test data, masking or tokenization?
Masking. Test environments need realistic values, not the originals. Tokenized test data keeps a link to production through the vault, and random tokens often fail format validation. Mask a copy, replace the tokens in it, and keep tokenization for production.





