Deterministic pseudonyms — same value, same pseudonym, joins intact
Random replacement breaks joins. A deterministic pseudonym keeps the relationship.
The short answer
pseudonym = HMAC-SHA-256(salt, type + original). With the same salt, the same original always gives the same pseudonym, so joins across tables survive.
Why random replacement breaks tests
The customer table and the order table share an email. Replace it randomly in each and the join returns nothing.
A deterministic pseudonym maps the same input to the same output in both tables, so join results and aggregates keep the shape of the original.
Managing the salt
The salt is the secret key of the mapping. Without it the original is hard to invert; with the same salt the output is reproducible.
Each session starts with a new salt, so if you need the same pseudonyms across runs, note the salt down and enter it again. It is never stored on a server.
How the shape is kept
Output shape follows the type, using the original's length and separators.
- Email: u + 8 hash characters @example.invalid
- Phone: 010-0000- + 4 hash digits (with +82 it becomes +82-10-0000-…)
- Card: 4111 1111 1111 + 3 hash digits + Luhn check digit
- Resident no.: hash-derived birth date and gender + 6 digits + checksum
- IPv4: 198.18.x.y (the benchmarking range)
- IPv6: 2001:db8: + four hash groups (the documentation range)
Limits
Values with few possibilities, such as phone numbers, can be found by guessing if the salt leaks. Use full redaction for anything you publish.
Keeping the same value mapped to the same pseudonym is itself information. If two records must not be linkable, use full redaction instead.
Example
Transform twice with the same salt and the output is byte-for-byte identical.
INSERT INTO orders (order_id, email) VALUES
(1, 'user01@example.invalid'),
(2, 'user01@example.invalid');
-- deterministic pseudonym → both rows get the same email.
Questions
Can I recover the original if I lose the salt?
No. A pseudonym cannot be reversed, and without the old salt you cannot reproduce earlier pseudonyms either. Keep the salt somewhere safe.
Does a leaked salt expose the originals?
Low-entropy values such as phone numbers can be guessed. Long values such as cards and emails are relatively safer, but still unsuitable for publication.
What is the difference between pseudonymisation and anonymisation?
Pseudonymisation keeps the ability to link records about the same person; anonymisation removes the link. Use pseudonyms for test joins, anonymisation for published data.
Sources
- NIST SP 800-188 — De-Identifying Government Datasets
- RFC 2104 — HMAC
- GDPR Article 4(5) — pseudonymisation
Every example here can be pasted into the workbench as it is.
Open the workbench