Masking a card number on a report is easy. Keeping the card number useful while nobody can read it is harder. The settlement job still has to join card records across tables, the support desk still needs the last four digits to match a caller, and the fraud team occasionally needs the full number for a chargeback form. Tokens solve this: a value with the same shape as the original that carries none of its meaning. InsightAIShield makes tokens three ways — computed with format-preserving encryption, drawn at random and sealed in a vault, or hashed one way — and this post is about choosing between them, column by column, on the fictional Northmere Bank’s demo estate.
In short
- Three modes, one format catalogue. fpe computes the token with NIST FF1 or FF3-1, vault draws a random token and seals the value with AES-GCM, one-way renders a keyed HMAC-SHA256 in the value’s shape and can never be reversed.
- The shape stays. Seven built-in formats keep length, separators and, where you choose, the first or last four characters in clear, so validations, joins and look-ups keep working.
- Keys are references. A key row names where the key lives (
env://,aws-kms://,aws-sm://, a file); the material is never stored or shown, and rotation keeps old tokens readable. - Detokenizing is a person’s act. It needs a purpose in words and permission for the column, is capped at 1,000 tokens per 60 minutes per person by default, and every attempt is recorded, allowed or not.
What a token has to do
A token stands in for a sensitive value wherever the value itself isn’t needed. That sounds like a single requirement, but in practice a column asks four questions of its token:
- Does it fit? A card number column with a Luhn check, a fixed width and dashes in set places will reject a token that looks like a UUID. Applications break on shape before they break on meaning.
- Does it join? If the same card number appears in the card table and in the dispute table, both must get the same token, or every report that links them falls apart.
- Can it come back? Some columns need the clear value again for a narrow purpose (a chargeback, a regulator’s request). Others never should.
- Where does the secret live? Either the value is recoverable from the token with a key, or it is stored somewhere and the token is a pointer to it. Each choice puts the risk in a different place.
The three modes in InsightAIShield answer these differently, and all three use the same catalogue of formats, so the decision about shape is separate from the decision about recoverability.
Formats: the shape, chosen once
A format says which characters are replaced and which stay. There are seven built in. The numeric ones replace digits with digits and leave separators and punctuation where they were; the letters-and-digits ones do the same for alphanumeric values such as account identifiers or IBAN-like strings. Each comes in three variants: everything replaced, the last four left in clear (card and account look-ups), or the first four left in clear (issuer ranges). The seventh, a random GUID, carries nothing of the value at all and is only used in vault mode. A team that needs something else adds a custom format: its own alphabet, how many characters to keep on the left or right, and an optional prefix.
NUMERIC_SAME_LAST_FOUR turns 4111-1111-1111-1111 into 9190-9097-4224-1111: same dashes, same length, same last four.The last-four variant is the one most banks reach for first. A support agent confirming “the card ending 1111” sees exactly what they need, and the remaining twelve digits are noise with the right shape. The first-four variant suits analytics on issuer ranges, where the bank identification digits matter and the account digits don’t.
Three ways to make the token
One format catalogue, three modes. The format decides the shape; the mode decides how the token is made and whether it can come back.
Format-preserving encryption (fpe)
FF1 and FF3-1 are the two modes of NIST SP 800-38G Rev. 1. They encrypt a string of numerals into another
string of the same length over the same alphabet, so a sixteen-digit number becomes a sixteen-digit
number. Nothing is stored: the token is computed from the value, the key and a tweak, and the clear value is
computed back from the token with the same key and tweak. InsightAIShield derives the tweak per column from
the column’s scope (for example cards_mysql.cards.card.pan), so the same card number in
two different columns gives two different tokens, while the same number in the same column always gives
the same token and still joins.
Two details matter here. First, the implementation checks the standard’s length rules for each alphabet before it encrypts, so a value too short to encrypt safely is refused rather than weakly encrypted. Second, FF3-1 uses the 56-bit tweak of the revised standard; the original FF3, withdrawn after a published attack, exists in the code only so the tests can check it against NIST’s samples, and is never used to tokenize.
Vaultless tokens are the right choice when volume is high and the clear value is needed back by systems, not by people browsing a table: a payment pipeline that tokenizes at ingestion and detokenizes at the point of settlement, for instance. The cost is that whoever holds the key and the scope can reverse every token, so the key is the whole secret.
The vault
In vault mode the token is drawn at random in the chosen format and the clear value is sealed with AES-GCM and kept in the vault. A keyed HMAC of the format, scope and value acts as the lookup, so the same value in the same column always returns the same token: joins work exactly as with FPE. Reversing a token means finding its row and unsealing it, which happens only through the detokenize request described below. The token itself contains no information about the value, so a token leaked without the vault is just a string. This suits values people occasionally need in clear, such as SSNs in a KYC lake or card numbers in a dispute table.
One-way
One-way tokens are a keyed HMAC-SHA256 rendered in the format’s shape. They are deterministic, so they still join and still count distinct values, and nobody can turn them back into the original, with or without the vault. Use them for analytics columns where nobody should ever see the value again: an email address used only to count unique customers in the warehouse is the demo’s example.
| fpe (FF1 / FF3-1) | vault | one-way | |
|---|---|---|---|
| Token keeps the shape | Yes, same length and alphabet | Yes, per the format (or a GUID) | Yes, per the format |
| Same value, same column, same token | Yes (per-column tweak) | Yes (keyed HMAC lookup) | Yes |
| Stored | Nothing but a listing row | The value, sealed with AES-GCM | Nothing but a listing row |
| Back to clear | With the key, through detokenize | From the vault, through detokenize | Never |
| Typical column | High-volume pipeline fields | SSNs, PANs people sometimes need | Analytics identifiers |
What the demo vault holds
On Northmere’s estate the vault lists 11 tokens across 4 columns, one of them one-way: card numbers from the cards platform, three SSNs from the KYC table in the lake, and a one-way email from the warehouse’s customer view. The vault page shows each token, its format, its scope, the key and key version that made it, its kind and how often it has been used. The clear values are never on this page.
Keys that are only references
A key in InsightAIShield is a row that names an algorithm (FF1 or FF3-1), a reference to where the key
material lives, a version and a status. The demo has two, demo_ff1 and demo_ff31,
both pointing at env://SHIELD_TOKEN_KEY; in production the reference is a KMS or secrets-manager
path. From the one master key, separate sub-keys are derived with HKDF-SHA256 for encryption, sealing and
hashing, so no single derived key does two jobs.
Rotation retires the current version and activates the next with a new reference. Tokens remember the
version that made them (demo_ff1@v1 in the vault listing), so tokens made before a rotation
still detokenize, and new tokens use the new key. The audit line says exactly that: which version was
retired, which is active.
Tokens on the way out, not just at rest
Tokenizing a column at rest is a migration. InsightAIShield can also tokenize on the response, which needs
no migration at all. A policy rule of type TOKENIZE names a format, a key and a scope; when a
query reads that column through the proxy or the query gateway, the value in the result set is replaced
with its token before it leaves. The query itself is unchanged. The demo’s customer support
assistant, an AI agent, reads account details this way:
The agent can still read a customer the last four digits of an account and still pass the token to the
next tool call, but nothing it holds, logs or sends to a model is a real account number. A HASH
rule does the same with a one-way token. When two rules protect one column, the stronger wins: block, then
tokenize, then hash, then redact, then mask.
Getting the clear value back
Every token mode except one-way can be reversed, so reversal is where the controls sit. A detokenize request
needs three things: the tokens and their scope, a purpose written in words (a short phrase with real words
in it; “asdf” is refused), and a requester who is allowed to see that scope in clear, a data
security lead by default. An agent is never allowed: the vault refuses an agent as the requester and
records the attempt. Each person also has an allowance, 1,000 tokens per 60 minutes by default, set with
SHIELD_DETOKENIZE_LIMIT and SHIELD_DETOKENIZE_PERIOD_MINUTES.
An AI agent is refused outright. A person must be allowed to see this scope in clear.
The purpose must be in words. It is stored with the request and shown on the Detokenize requests tab.
Tokens already revealed to this person in the period, against the allowance.
Values returned; the request row and an audit line keep who, why, which scope, how many and the outcome.
In the demo, two requests sit side by side. An analyst asked for one card number “looking at the card for a customer call” and was denied: not allowed to see that scope in clear. The data security administrator asked for two “for chargeback 7781: the card network asks for the full PAN on the dispute form” and was allowed; two values were revealed. Both rows stay.
Choosing, column by column
Start from the question each column has to answer. If nobody should ever see the value again, use one-way and stop worrying about it. If people need it back occasionally and you want leaked tokens to be worthless on their own, use the vault. If systems need it back at volume and you are comfortable that the key is the secret, use FF1 (or FF3-1 where an existing standard requires it). In every case pick the format by what the column’s consumers check: the last four for look-ups, the first four for issuer analytics, full replacement otherwise.
Shape is a format decision. Recoverability is a mode decision. Reversal is a person’s decision.
Keeping the three apart is what lets a bank tokenize widely without breaking its applications, and still answer who saw which clear value, when and why.
Where people stay in charge
- Agents never detokenize: the vault refuses an agent as the requester, and a person states the purpose in words.
- Every agent action is capped at L2, “ask first”: an agent prepares, and a person confirms, activates, revokes, sends or decides.
- A policy version goes live only when a second lead, not the person who proposed it, approves it.
- A revocation is proposed by one reviewer and approved by another; the REVOKE statement is kept on the record for your DBA to run.
- Detokenizing needs a stated purpose, is recorded, and is capped per person per period.
- SIEM batches and attestation requests are held until a person releases them.