Privacy engineering primitives: differential privacy mechanisms + budget ledger, PII/PHI masking, CN-compliant masking (GB/T 37964), MIMIC-style date shifting, k-anonymity, secrets/text redaction with reversible restore, and format-preserving encryption (FF3/FF3-1, NIST SP 800-38G)
Compatibility Matrix
This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.5.5 | 1.5.6 | 2.0.0 | 2.0.1 |
|---|---|---|---|---|
| Linux AMD64 | ||||
| Linux ARM64 | ||||
| macOS AMD64 | ||||
| macOS ARM64 | ||||
| Windows AMD64 | ||||
| Windows ARM64 | ||||
| WebAssembly |
Installing and Loading
INSTALL privacy FROM community;
LOAD privacy;
Example
SELECT privacy('{"op":"mask_cn","v":"13812345678"}');
About privacy
Privacy engineering primitives for DuckDB, as a native Rust extension. Ported 1:1 from the duckdb-luajit-libs privacy lib.
Everything is reachable through one dispatcher that mirrors the source API, plus single-argument convenience scalars:
SELECT privacy('{"op":"mask_cn","v":"110101199003071234","kind":"idcard","mode":"birth"}');
SELECT privacy('{"op":"fpe_encode","v":"1234567890","key":"00000000000000000000000000000000","algo":"ff31"}');
Ops (18): dp_count / dp_sum / dp_mean / laplace / dp_compose / dp_alloc / dp_budget (differential privacy + epsilon budget ledger), mask / mask_cn (PII masking, CN-compliant), dateshift / dateoffset (MIMIC-style deterministic date shifting), kanon (k-anonymity), kanon_report (l-diversity / t-closeness / suppression), redact_text / redact_secrets / restore_text (PHI + credential redaction with reversible restore), fpe_encode / fpe_decode / fpe_luhn / fpe_token (FF3 / FF3-1 format-preserving encryption).
Verified: 24 unit tests; FPE checked differentially against an independent Python oracle (15 NIST FF3 + 18 FF3-1 vectors, encrypt + decrypt).
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| dateshift | scalar | NULL | NULL | |
| dp_count | scalar | NULL | NULL | |
| dp_sum | scalar | NULL | NULL | |
| fpe_decode | scalar | NULL | NULL | |
| fpe_encode | scalar | NULL | NULL | |
| laplace | scalar | NULL | NULL | |
| mask | scalar | NULL | NULL | |
| mask_cn | scalar | NULL | NULL | |
| privacy | scalar | NULL | NULL | |
| redact_secrets | scalar | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
| name | description | input_type | scope | aliases | typed_value |
|---|---|---|---|---|---|
| temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |