pg_enigma
Encrypted postgres data type
Repository
SoftwareLibreMx/pg_enigma
https://github.com/SoftwareLibreMx/pg_enigma
Source
pg_enigma-0.5.0.tar.gz
pg_enigma-0.5.0.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_enigma | 0.5.0 | SEC | MIT | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7070 | pg_enigma | No | Yes | No | Yes | No | No | - |
| Related | pgsodium pgcryptokey pgcrypto pg_tde |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.5.0 | 1817161514 | pg_enigma | - |
| RPM | PIGSTY | 0.5.0 | 1817161514 | pg_enigma_$v | - |
| DEB | PIGSTY | 0.5.0 | 1817161514 | postgresql-$v-enigma | - |
Build
You can build the RPM / DEB packages for pg_enigma using pig build:
pig build pkg pg_enigma # build RPM / DEB packages
Install
You can install pg_enigma directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_enigma; # Install for current active PG version
pig ext install -y pg_enigma -v 18 # PG 18
pig ext install -y pg_enigma -v 17 # PG 17
pig ext install -y pg_enigma -v 16 # PG 16
pig ext install -y pg_enigma -v 15 # PG 15
pig ext install -y pg_enigma -v 14 # PG 14
dnf install -y pg_enigma_18 # PG 18
dnf install -y pg_enigma_17 # PG 17
dnf install -y pg_enigma_16 # PG 16
dnf install -y pg_enigma_15 # PG 15
dnf install -y pg_enigma_14 # PG 14
apt install -y postgresql-18-enigma # PG 18
apt install -y postgresql-17-enigma # PG 17
apt install -y postgresql-16-enigma # PG 16
apt install -y postgresql-15-enigma # PG 15
apt install -y postgresql-14-enigma # PG 14
Create Extension:
CREATE EXTENSION pg_enigma;
Usage
pg_enigma: Encrypted data type for PostgreSQL using PGP and RSA keys
pg_enigma provides an Enigma encrypted data type for PostgreSQL that encrypts data at rest using PGP or OpenSSL RSA keys. Data is stored encrypted and only decrypted when the private key is loaded into memory.
CREATE EXTENSION IF NOT EXISTS pg_enigma;
PGP Key Encryption
-- Create a table with an encrypted column (key slot 2)
CREATE TABLE test_pgp (
id SERIAL,
val Enigma(2)
);
-- Load the public key for encryption
SELECT set_public_key_from_file(2, '/path/to/public-key.asc');
-- Insert data (automatically encrypted with the public key)
INSERT INTO test_pgp (val) VALUES ('A secret value'::Text);
-- Without private key, SELECT returns encrypted PGP message
SELECT * FROM test_pgp;
-- Load private key to enable decryption
SELECT set_private_key_from_file(2, '/path/to/private-key.asc', 'passphrase');
-- Now SELECT returns decrypted plaintext
SELECT * FROM test_pgp;
-- id | val
-- ----+----------------
-- 1 | A secret value
-- Remove private key from memory
SELECT forget_private_key(2);
-- Subsequent SELECTs return encrypted data again
RSA Key Encryption
CREATE TABLE test_rsa (
id SERIAL,
val Enigma(3)
);
SELECT set_public_key_from_file(3, '/path/to/alice_public.pem');
INSERT INTO test_rsa (val) VALUES ('Another secret value'::Text);
SELECT set_private_key_from_file(3, '/path/to/alice_private.pem', 'passphrase');
SELECT * FROM test_rsa;
SELECT forget_private_key(3);
Functions
| Function | Description |
|---|---|
set_public_key_from_file(slot, path) | Load a public key for encryption |
set_private_key_from_file(slot, path, passphrase) | Load a private key for decryption |
forget_private_key(slot) | Remove private key from memory |
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.