pg_themis
pg_themis · PostgreSQL encryption and decryption functions backed by the Themis cryptographic library.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100042 | pg_themis | pg_themis | 1.0 | SEC | Apache-2.0 | C |
Usage
Sources:
- Pinned upstream README
- Version 1.0 installation SQL
- Pinned C implementation
- Pinned extension control file
- Current Themis product documentation
pg_themis version 1.0 is a 2016 PostgreSQL binding for the external Themis cryptographic library. It exposes Secure Cell Seal encryption and decryption with a symmetric key, plus Secure Message encryption with a recipient public key and decryption with the corresponding private key.
Secure Cell round trip
Install a compatible system Themis library first. This isolated example uses pgcrypto only to create a temporary key:
The extension does not generate, store, rotate, authorize, or audit application keys. Those controls remain the caller’s responsibility.
Unsafe legacy Secure Message path
The Secure Message helper narrows plaintext or ciphertext length to an unsigned one-byte value before calling Themis. Inputs longer than 255 bytes are therefore truncated modulo 256. Its decrypt path also reads an embedded 32-bit public-key length before first proving the ciphertext is at least four bytes, then trusts that length for pointer arithmetic. Malformed ciphertext can reach out-of-bounds reads. Do not use the Secure Message SQL functions from this snapshot.
All four functions receive plaintext or keys as SQL bytea arguments. Query text, parameters, activity views, logs, tracing, errors, backups, and memory can expose secrets. The installation SQL leaves default PUBLIC execution in place. Revoke it, keep key material outside SQL literals, and use a reviewed key-management design.
The upstream PostgreSQL binding has not changed since 2016, and its broad PostgreSQL 9.1+ statement is not a current compatibility guarantee. Current Themis itself may evolve independently of this binding. Pin and test the exact library ABI, use authenticated test vectors, fuzz malformed and boundary-length inputs, and prefer a maintained integration for production cryptography.