跳转到主要内容

pg_enigma

PostgreSQL 加密数据类型

pg_enigma · PostgreSQL 加密数据类型

概览

ID扩展软件包版本类别许可证编程语言
7090pg_enigmapg_enigma0.5.0SECMITRust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d--否是否是否否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY0.5.019 18 17 16 15pg_enigma-
RPMPIGSTY0.5.019 18 17 16 15pg_enigma_$v-
DEBPIGSTY0.5.019 18 17 16 15postgresql-$v-enigma-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el8.aarch64N/APIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el9.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el9.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el10.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
el10.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d12.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d12.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d13.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
d13.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u22.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u22.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u24.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u24.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u26.x86_64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
u26.aarch64PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0PIGSTY 0.5.0
软件包版本平台仓库大小下载
pg_enigma_180.5.0el8.x86_64pigsty3.4 MiBpg_enigma_18-0.5.0-3PIGSTY.el8.x86_64.rpm
pg_enigma_180.5.0el8.aarch64pigsty3.0 MiBpg_enigma_18-0.5.0-3PIGSTY.el8.aarch64.rpm
pg_enigma_180.5.0el9.x86_64pigsty3.8 MiBpg_enigma_18-0.5.0-4PGSTY.el9.x86_64.rpm
pg_enigma_180.5.0el9.aarch64pigsty3.5 MiBpg_enigma_18-0.5.0-4PGSTY.el9.aarch64.rpm
pg_enigma_180.5.0el10.x86_64pigsty3.8 MiBpg_enigma_18-0.5.0-4PGSTY.el10.x86_64.rpm
pg_enigma_180.5.0el10.aarch64pigsty3.5 MiBpg_enigma_18-0.5.0-4PGSTY.el10.aarch64.rpm
postgresql-18-enigma0.5.0d12.x86_64pigsty2.6 MiBpostgresql-18-enigma_0.5.0-4PGSTY~bookworm_amd64.deb
postgresql-18-enigma0.5.0d12.aarch64pigsty2.3 MiBpostgresql-18-enigma_0.5.0-4PGSTY~bookworm_arm64.deb
postgresql-18-enigma0.5.0d13.x86_64pigsty2.6 MiBpostgresql-18-enigma_0.5.0-4PGSTY~trixie_amd64.deb
postgresql-18-enigma0.5.0d13.aarch64pigsty2.3 MiBpostgresql-18-enigma_0.5.0-4PGSTY~trixie_arm64.deb
postgresql-18-enigma0.5.0u22.x86_64pigsty2.9 MiBpostgresql-18-enigma_0.5.0-4PGSTY~jammy_amd64.deb
postgresql-18-enigma0.5.0u22.aarch64pigsty2.7 MiBpostgresql-18-enigma_0.5.0-4PGSTY~jammy_arm64.deb
postgresql-18-enigma0.5.0u24.x86_64pigsty2.9 MiBpostgresql-18-enigma_0.5.0-4PGSTY~noble_amd64.deb
postgresql-18-enigma0.5.0u24.aarch64pigsty2.7 MiBpostgresql-18-enigma_0.5.0-4PGSTY~noble_arm64.deb
postgresql-18-enigma0.5.0u26.x86_64pigsty2.9 MiBpostgresql-18-enigma_0.5.0-4PGSTY~resolute_amd64.deb
postgresql-18-enigma0.5.0u26.aarch64pigsty2.7 MiBpostgresql-18-enigma_0.5.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_enigma_170.5.0el8.x86_64pigsty3.4 MiBpg_enigma_17-0.5.0-3PIGSTY.el8.x86_64.rpm
pg_enigma_170.5.0el8.aarch64pigsty3.0 MiBpg_enigma_17-0.5.0-3PIGSTY.el8.aarch64.rpm
pg_enigma_170.5.0el9.x86_64pigsty3.8 MiBpg_enigma_17-0.5.0-4PGSTY.el9.x86_64.rpm
pg_enigma_170.5.0el9.aarch64pigsty3.5 MiBpg_enigma_17-0.5.0-4PGSTY.el9.aarch64.rpm
pg_enigma_170.5.0el10.x86_64pigsty3.8 MiBpg_enigma_17-0.5.0-4PGSTY.el10.x86_64.rpm
pg_enigma_170.5.0el10.aarch64pigsty3.5 MiBpg_enigma_17-0.5.0-4PGSTY.el10.aarch64.rpm
postgresql-17-enigma0.5.0d12.x86_64pigsty2.6 MiBpostgresql-17-enigma_0.5.0-4PGSTY~bookworm_amd64.deb
postgresql-17-enigma0.5.0d12.aarch64pigsty2.3 MiBpostgresql-17-enigma_0.5.0-4PGSTY~bookworm_arm64.deb
postgresql-17-enigma0.5.0d13.x86_64pigsty2.6 MiBpostgresql-17-enigma_0.5.0-4PGSTY~trixie_amd64.deb
postgresql-17-enigma0.5.0d13.aarch64pigsty2.3 MiBpostgresql-17-enigma_0.5.0-4PGSTY~trixie_arm64.deb
postgresql-17-enigma0.5.0u22.x86_64pigsty2.9 MiBpostgresql-17-enigma_0.5.0-4PGSTY~jammy_amd64.deb
postgresql-17-enigma0.5.0u22.aarch64pigsty2.7 MiBpostgresql-17-enigma_0.5.0-4PGSTY~jammy_arm64.deb
postgresql-17-enigma0.5.0u24.x86_64pigsty2.9 MiBpostgresql-17-enigma_0.5.0-4PGSTY~noble_amd64.deb
postgresql-17-enigma0.5.0u24.aarch64pigsty2.7 MiBpostgresql-17-enigma_0.5.0-4PGSTY~noble_arm64.deb
postgresql-17-enigma0.5.0u26.x86_64pigsty2.9 MiBpostgresql-17-enigma_0.5.0-4PGSTY~resolute_amd64.deb
postgresql-17-enigma0.5.0u26.aarch64pigsty2.7 MiBpostgresql-17-enigma_0.5.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_enigma_160.5.0el8.x86_64pigsty3.4 MiBpg_enigma_16-0.5.0-3PIGSTY.el8.x86_64.rpm
pg_enigma_160.5.0el8.aarch64pigsty3.0 MiBpg_enigma_16-0.5.0-3PIGSTY.el8.aarch64.rpm
pg_enigma_160.5.0el9.x86_64pigsty3.8 MiBpg_enigma_16-0.5.0-4PGSTY.el9.x86_64.rpm
pg_enigma_160.5.0el9.aarch64pigsty3.5 MiBpg_enigma_16-0.5.0-4PGSTY.el9.aarch64.rpm
pg_enigma_160.5.0el10.x86_64pigsty3.8 MiBpg_enigma_16-0.5.0-4PGSTY.el10.x86_64.rpm
pg_enigma_160.5.0el10.aarch64pigsty3.5 MiBpg_enigma_16-0.5.0-4PGSTY.el10.aarch64.rpm
postgresql-16-enigma0.5.0d12.x86_64pigsty2.6 MiBpostgresql-16-enigma_0.5.0-4PGSTY~bookworm_amd64.deb
postgresql-16-enigma0.5.0d12.aarch64pigsty2.3 MiBpostgresql-16-enigma_0.5.0-4PGSTY~bookworm_arm64.deb
postgresql-16-enigma0.5.0d13.x86_64pigsty2.6 MiBpostgresql-16-enigma_0.5.0-4PGSTY~trixie_amd64.deb
postgresql-16-enigma0.5.0d13.aarch64pigsty2.3 MiBpostgresql-16-enigma_0.5.0-4PGSTY~trixie_arm64.deb
postgresql-16-enigma0.5.0u22.x86_64pigsty2.9 MiBpostgresql-16-enigma_0.5.0-4PGSTY~jammy_amd64.deb
postgresql-16-enigma0.5.0u22.aarch64pigsty2.7 MiBpostgresql-16-enigma_0.5.0-4PGSTY~jammy_arm64.deb
postgresql-16-enigma0.5.0u24.x86_64pigsty2.9 MiBpostgresql-16-enigma_0.5.0-4PGSTY~noble_amd64.deb
postgresql-16-enigma0.5.0u24.aarch64pigsty2.7 MiBpostgresql-16-enigma_0.5.0-4PGSTY~noble_arm64.deb
postgresql-16-enigma0.5.0u26.x86_64pigsty2.9 MiBpostgresql-16-enigma_0.5.0-4PGSTY~resolute_amd64.deb
postgresql-16-enigma0.5.0u26.aarch64pigsty2.7 MiBpostgresql-16-enigma_0.5.0-4PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_enigma_150.5.0el8.x86_64pigsty3.4 MiBpg_enigma_15-0.5.0-3PIGSTY.el8.x86_64.rpm
pg_enigma_150.5.0el8.aarch64pigsty3.0 MiBpg_enigma_15-0.5.0-3PIGSTY.el8.aarch64.rpm
pg_enigma_150.5.0el9.x86_64pigsty3.7 MiBpg_enigma_15-0.5.0-4PGSTY.el9.x86_64.rpm
pg_enigma_150.5.0el9.aarch64pigsty3.5 MiBpg_enigma_15-0.5.0-4PGSTY.el9.aarch64.rpm
pg_enigma_150.5.0el10.x86_64pigsty3.7 MiBpg_enigma_15-0.5.0-4PGSTY.el10.x86_64.rpm
pg_enigma_150.5.0el10.aarch64pigsty3.5 MiBpg_enigma_15-0.5.0-4PGSTY.el10.aarch64.rpm
postgresql-15-enigma0.5.0d12.x86_64pigsty2.6 MiBpostgresql-15-enigma_0.5.0-4PGSTY~bookworm_amd64.deb
postgresql-15-enigma0.5.0d12.aarch64pigsty2.3 MiBpostgresql-15-enigma_0.5.0-4PGSTY~bookworm_arm64.deb
postgresql-15-enigma0.5.0d13.x86_64pigsty2.6 MiBpostgresql-15-enigma_0.5.0-4PGSTY~trixie_amd64.deb
postgresql-15-enigma0.5.0d13.aarch64pigsty2.3 MiBpostgresql-15-enigma_0.5.0-4PGSTY~trixie_arm64.deb
postgresql-15-enigma0.5.0u22.x86_64pigsty2.9 MiBpostgresql-15-enigma_0.5.0-4PGSTY~jammy_amd64.deb
postgresql-15-enigma0.5.0u22.aarch64pigsty2.7 MiBpostgresql-15-enigma_0.5.0-4PGSTY~jammy_arm64.deb
postgresql-15-enigma0.5.0u24.x86_64pigsty2.9 MiBpostgresql-15-enigma_0.5.0-4PGSTY~noble_amd64.deb
postgresql-15-enigma0.5.0u24.aarch64pigsty2.7 MiBpostgresql-15-enigma_0.5.0-4PGSTY~noble_arm64.deb
postgresql-15-enigma0.5.0u26.x86_64pigsty2.9 MiBpostgresql-15-enigma_0.5.0-4PGSTY~resolute_amd64.deb
postgresql-15-enigma0.5.0u26.aarch64pigsty2.7 MiBpostgresql-15-enigma_0.5.0-4PGSTY~resolute_arm64.deb

源码

pig build pkg pg_enigma;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

pig repo add pgsql -u   # add both repo and update cache

使用 pig 安装扩展。

pig install pg_enigma;		# install by package name

pig install pg_enigma -v 19;   # install for PG 19
pig install pg_enigma -v 18;   # install for PG 18
pig install pg_enigma -v 17;   # install for PG 17
pig install pg_enigma -v 16;   # install for PG 16
pig install pg_enigma -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pg_enigma;

用法

pg_enigma: 使用 PGP 和 RSA 密钥的 PostgreSQL 加密数据类型

pg_enigma 为 PostgreSQL 提供 Enigma 加密数据类型,使用 PGP 或 OpenSSL RSA 密钥对静态数据进行加密。数据以加密形式存储,仅在私钥加载到内存中时才进行解密。

CREATE EXTENSION IF NOT EXISTS pg_enigma;

PGP 密钥加密

-- 创建带加密列的表(密钥槽 2)
CREATE TABLE test_pgp (
    id SERIAL,
    val Enigma(2)
);

-- 加载公钥用于加密
SELECT set_public_key_from_file(2, '/path/to/public-key.asc');

-- 插入数据(自动使用公钥加密)
INSERT INTO test_pgp (val) VALUES ('A secret value'::Text);

-- 没有私钥时,SELECT 返回加密的 PGP 消息
SELECT * FROM test_pgp;

-- 加载私钥以启用解密
SELECT set_private_key_from_file(2, '/path/to/private-key.asc', 'passphrase');

-- 现在 SELECT 返回解密的明文
SELECT * FROM test_pgp;
-- id |      val
-- ----+----------------
--   1 | A secret value

-- 从内存中移除私钥
SELECT forget_private_key(2);
-- 后续 SELECT 再次返回加密数据

RSA 密钥加密

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);

函数

函数描述
set_public_key_from_file(slot, path)加载公钥用于加密
set_private_key_from_file(slot, path, passphrase)加载私钥用于解密
forget_private_key(slot)从内存中移除私钥

表格阅读器