Format-preserving encryption for PostgreSQL — native Rust extension powered by Cyphera.
Built on cyphera from crates.io via pgrx.
docker compose up -d
psql -h localhost -U postgres -d cyphera_demo
# password: cypheraSELECT cyphera_protect('ssn', '123-45-6789') AS protected;
-- → T01i6J-xF-07pX
SELECT cyphera_access(cyphera_protect('ssn', '123-45-6789')) AS accessed;
-- → 123-45-6789docker build -t cyphera-postgres .Requires Rust, cargo-pgrx, and PostgreSQL 17 dev headers:
cargo install cargo-pgrx --version 0.13.1 --locked
cargo pgrx init --pg17 /usr/lib/postgresql/17/bin/pg_config
cargo build --features pg17Use the provided docker-compose.yml — it builds the extension and creates a Postgres instance with Cyphera loaded.
- Build the extension:
cargo pgrx package --pg-config /path/to/pg_config - Copy the built files to your Postgres extension directory
- Place
cyphera.jsonat/etc/cyphera/cyphera.json - In psql:
CREATE EXTENSION cyphera_postgres;
-- Protect (tagged, dashes preserved)
SELECT cyphera_protect('ssn', '123-45-6789');
-- → T01i6J-xF-07pX
-- Access using embedded tag (no policy name needed)
SELECT cyphera_access(cyphera_protect('ssn', '123-45-6789'));
-- → 123-45-6789
-- Bulk protect
SELECT name, ssn, cyphera_protect('ssn', ssn) AS protected
FROM customers;
-- In-place protection on INSERT
INSERT INTO customers_protected (name, ssn)
SELECT name, cyphera_protect('ssn', ssn) FROM customers;- Policy file:
/etc/cyphera/cyphera.json(override withCYPHERA_POLICY_FILEenv var) - Policy loaded once at first function call — restart Postgres to reload
- Errors return as SQL errors — visible in psql and application logs
- Extension loaded:
SELECT * FROM pg_extension WHERE extname = 'cyphera_postgres';
- Build new extension with updated
cypheracrate version inCargo.toml - Replace extension files in Postgres extension directory
ALTER EXTENSION cyphera_postgres UPDATE;- Restart Postgres
- Extension not found —
CREATE EXTENSION cyphera_postgres;not run, or files not in extension dir - "Unknown policy" — check
CYPHERA_POLICY_FILEpath and cyphera.json contents - Build fails — ensure pgrx version matches (0.13.x), Postgres dev headers installed
{
"policies": {
"ssn": { "engine": "ff1", "key_ref": "demo-key", "tag": "T01" },
"credit_card": { "engine": "ff1", "key_ref": "demo-key", "tag": "T02" }
},
"keys": {
"demo-key": { "material": "2B7E151628AED2A6ABF7158809CF4F3C" }
}
}- PGXN package for easy
pgxn install - Cloud provider extension registries (AWS RDS, GCP Cloud SQL, Supabase)
- PostgreSQL 14/15/16 support (currently 17 only)
- Performance benchmarking vs application-layer encryption
Apache 2.0 — Copyright 2026 Horizon Digital Engineering LLC