cryptint

加密INT与BIGINT类型

概览

扩展包名版本分类许可证语言
cryptint1.0.0UTILPostgreSQLC
ID扩展名BinLibLoadCreateTrustReloc模式
4450cryptint-
相关扩展hashlib shacrypt pguecc pgcrypto gzip bzip zstd http

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY1.0.01817161514cryptint-
RPMPIGSTY1.0.01817161514cryptint_$v-
DEBPIGSTY1.0.01817161514postgresql-$v-cryptint-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u22.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u22.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u24.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
u24.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0

构建

您可以使用 pig build 命令构建 cryptint 扩展的 RPM / DEB 包:

pig build pkg cryptint         # 构建 RPM / DEB 包

安装

您可以直接安装 cryptint 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install cryptint;          # 当前活跃 PG 版本安装
pig ext install -y cryptint -v 18  # PG 18
pig ext install -y cryptint -v 17  # PG 17
pig ext install -y cryptint -v 16  # PG 16
pig ext install -y cryptint -v 15  # PG 15
pig ext install -y cryptint -v 14  # PG 14
dnf install -y cryptint_18       # PG 18
dnf install -y cryptint_17       # PG 17
dnf install -y cryptint_16       # PG 16
dnf install -y cryptint_15       # PG 15
dnf install -y cryptint_14       # PG 14
apt install -y postgresql-18-cryptint   # PG 18
apt install -y postgresql-17-cryptint   # PG 17
apt install -y postgresql-16-cryptint   # PG 16
apt install -y postgresql-15-cryptint   # PG 15
apt install -y postgresql-14-cryptint   # PG 14

创建扩展

CREATE EXTENSION cryptint;

用法

cryptint: 使用 SKIP32 和 XTEA 加解密整数

SKIP32(32 位整数加密)

基于 Skipjack 的 24 轮分组密码。使用 80 位(10 字节)密钥加密 32 位值。

SELECT skip32_encrypt(42, '\x00010203040506070809'::bytea);
-- 加密后的 int4

SELECT skip32_decrypt(175586429, '\x00010203040506070809'::bytea);
-- 0

往返示例:

SELECT i, skip32_encrypt(i, '\x00010203040506070809'::bytea) AS encrypted,
       skip32_decrypt(skip32_encrypt(i, '\x00010203040506070809'::bytea), '\x00010203040506070809'::bytea) AS decrypted
FROM generate_series(-3, 3) AS i;

XTEA(64 位整数加密)

64 轮分组密码。使用 128 位(16 字节)密钥加密 64 位值。

SELECT xtea_encrypt(42::bigint, '\x000102030405060708090a0b0c0d0e0f'::bytea);
-- 加密后的 bigint

SELECT xtea_decrypt(103200416458222088::bigint, '\x000102030405060708090a0b0c0d0e0f'::bytea);
-- 1

函数参考

函数描述
skip32_encrypt(int, bytea)使用 10 字节密钥加密 int4
skip32_decrypt(int, bytea)使用 10 字节密钥解密 int4
xtea_encrypt(bigint, bytea)使用 16 字节密钥加密 bigint
xtea_decrypt(bigint, bytea)使用 16 字节密钥解密 bigint

最后修改 2026-03-14: update extension metadata (953cbd0)