cryptint

Encryption functions for int and bigint values

Overview

PackageVersionCategoryLicenseLanguage
cryptint1.0.0UTILPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4450cryptintNoYesNoYesNoYes-
Relatedhashlib shacrypt pguecc pgcrypto gzip bzip zstd http

Version

TypeRepoVersionPG VerPackageDeps
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

Build

You can build the RPM / DEB packages for cryptint using pig build:

pig build pkg cryptint         # build RPM / DEB packages

Install

You can install cryptint 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 cryptint;          # Install for current active PG version
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:

CREATE EXTENSION cryptint;

Usage

cryptint: Encrypt and decrypt integers with SKIP32 and XTEA

SKIP32 (32-bit integer encryption)

Block cipher with 24 rounds based on Skipjack. Encrypts 32-bit values with an 80-bit (10-byte) key.

SELECT skip32_encrypt(42, '\x00010203040506070809'::bytea);
-- encrypted int4

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

Roundtrip example:

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-bit integer encryption)

Block cipher with 64 rounds. Encrypts 64-bit values with a 128-bit (16-byte) key.

SELECT xtea_encrypt(42::bigint, '\x000102030405060708090a0b0c0d0e0f'::bytea);
-- encrypted bigint

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

Functions Reference

FunctionDescription
skip32_encrypt(int, bytea)Encrypt int4 with 10-byte key
skip32_decrypt(int, bytea)Decrypt int4 with 10-byte key
xtea_encrypt(bigint, bytea)Encrypt bigint with 16-byte key
xtea_decrypt(bigint, bytea)Decrypt bigint with 16-byte key

Last Modified 2026-03-12: add pg extension catalog (95749bf)