permuteseq
Pseudo-randomly permute sequences with a format-preserving encryption on elements
Repository
dverite/permuteseq
https://github.com/dverite/permuteseq
Source
permuteseq-1.2.2.tar.gz
permuteseq-1.2.2.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
permuteseq | 1.2.2 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4550 | permuteseq | No | Yes | No | Yes | No | Yes | - |
| Related | pg_idkit random sequential_uuids pg_hashids pgx_ulid pg_uuidv7 uuid-ossp |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.2.2 | 1817161514 | permuteseq | - |
| RPM | PIGSTY | 1.2.2 | 1817161514 | permuteseq_$v | - |
| DEB | PIGSTY | 1.2.2 | 1817161514 | postgresql-$v-permuteseq | - |
Build
You can build the RPM / DEB packages for permuteseq using pig build:
pig build pkg permuteseq # build RPM / DEB packages
Install
You can install permuteseq 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 permuteseq; # Install for current active PG version
pig ext install -y permuteseq -v 18 # PG 18
pig ext install -y permuteseq -v 17 # PG 17
pig ext install -y permuteseq -v 16 # PG 16
pig ext install -y permuteseq -v 15 # PG 15
pig ext install -y permuteseq -v 14 # PG 14
dnf install -y permuteseq_18 # PG 18
dnf install -y permuteseq_17 # PG 17
dnf install -y permuteseq_16 # PG 16
dnf install -y permuteseq_15 # PG 15
dnf install -y permuteseq_14 # PG 14
apt install -y postgresql-18-permuteseq # PG 18
apt install -y postgresql-17-permuteseq # PG 17
apt install -y postgresql-16-permuteseq # PG 16
apt install -y postgresql-15-permuteseq # PG 15
apt install -y postgresql-14-permuteseq # PG 14
Create Extension:
CREATE EXTENSION permuteseq;
Usage
permuteseq: scalable pseudo-random permutations of sequences
Generate unique, non-sequential, random-looking series of numbers without storing previous values. Uses a Feistel cipher with cycle-walking for format-preserving encryption.
CREATE EXTENSION permuteseq;
Functions
| Function | Description |
|---|---|
permute_nextval(seq_oid, crypt_key bigint) | Advance sequence and return encrypted value within sequence bounds |
reverse_permute(seq_oid, value bigint, crypt_key bigint) | Compute original value from its permuted element |
range_encrypt_element(clear_val bigint, min_val bigint, max_val bigint, crypt_key bigint) | Encrypt a bigint in a given range |
range_decrypt_element(crypt_val bigint, min_val bigint, max_val bigint, crypt_key bigint) | Decrypt a previously encrypted value |
Examples
CREATE SEQUENCE s MINVALUE -10000 MAXVALUE 15000;
-- Generate random-looking unique values from a sequence
SELECT permute_nextval('s'::regclass, 123456789012345)
FROM generate_series(1, 10);
-- Reverse a permuted value back to the original
SELECT reverse_permute('s'::regclass, -545, 123456789012345);
-- -10000
-- Encrypt/decrypt within an arbitrary range
SELECT range_encrypt_element(91919191919, 1e10::bigint, 1e11::bigint, 123456789012345);
-- 83028080992
SELECT range_decrypt_element(83028080992, 1e10::bigint, 1e11::bigint, 123456789012345);
-- 91919191919
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.