permuteseq
permuteseq
permuteseq : Pseudo-randomly permute sequences with a format-preserving encryption on elements
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4550 | permuteseq
|
permuteseq
|
1.2.2 |
FUNC
|
PostgreSQL
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | pg_idkit
random
sequential_uuids
pg_hashids
pgx_ulid
pg_uuidv7
uuid-ossp
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.2.2 |
18
17
16
15
14
|
permuteseq |
- |
| RPM | PIGSTY
|
1.2.2 |
18
17
16
15
14
|
permuteseq_$v |
- |
| DEB | PIGSTY
|
1.2.2 |
18
17
16
15
14
|
postgresql-$v-permuteseq |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
el8.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
el9.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
el9.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
el10.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
el10.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
d12.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
d12.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
d13.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
d13.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
u22.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
u22.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
u24.x86_64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
u24.aarch64
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
PIGSTY 1.2.2
|
Source
pig build pkg permuteseq; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install permuteseq; # install via package name, for the active PG version
pig install permuteseq -v 18; # install for PG 18
pig install permuteseq -v 17; # install for PG 17
pig install permuteseq -v 16; # install for PG 16
pig install permuteseq -v 15; # install for PG 15
pig install permuteseq -v 14; # install for PG 14Create this extension with:
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);
-- 91919191919Last updated on