cryptint

cryptint

cryptint : Encryption functions for int and bigint values

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4450
cryptint
cryptint
1.0.0
UTIL
PostgreSQL
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
hashlib
shacrypt
pguecc
pgcrypto
gzip
bzip
zstd
http

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0.0
18
17
16
15
14
cryptint-
RPM
PIGSTY
1.0.0
18
17
16
15
14
cryptint_$v-
DEB
PIGSTY
1.0.0
18
17
16
15
14
postgresql-$v-cryptint-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el8.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el9.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
el10.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d12.aarch64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
d13.x86_64
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
PIGSTY 1.0.0
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

Source

pig build pkg cryptint;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install cryptint;		# install via package name, for the active PG version

pig install cryptint -v 18;   # install for PG 18
pig install cryptint -v 17;   # install for PG 17
pig install cryptint -v 16;   # install for PG 16
pig install cryptint -v 15;   # install for PG 15
pig install cryptint -v 14;   # install for PG 14

Create this extension with:

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 updated on