opyeb sqlmask

Deterministic pseudonyms — same value, same pseudonym, joins intact

2026-11-29 · 2 min read

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.

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

Every example here can be pasted into the workbench as it is.

Open the workbench