Articles

Writing your own PII redaction feels like a 20-minute job. That's the trap.

1 min read

I needed two unglamorous things in production: scrub personal info out of free text before it left our system, and encrypt a few identity fields at rest. Both are easy to hack together. Both quietly bite you later.

A record branches into one-way masking bars and a separate encryption path with a key and a return arrow from ciphertext to the original fields.

The redaction regexes most people write over-match. They'll happily turn an order number or a payment amount into "[redacted]" and you won't notice until a customer does. And homegrown field encryption usually hides a reused IV or a fast hash for key derivation, which is how you get crypto that only looks safe.

I already had this solved inside a real project, so I pulled the code out, stripped everything app-specific, and open-sourced it.

pii-toolkit-cy ships:

redact()

redact() for email / card / IBAN / phone, tuned NOT to eat bare integers like order ids

createPiiCipher()

createPiiCipher() with AES-256-GCM, a fresh IV per value, scrypt key derivation, and tamper detection on decrypt

zero dependencies, ESM, TypeScript types included.

It's deliberately small. It came out of something real, not a tutorial repo.

Original publication (external website)

Share this article