pgcryptokey
pgcryptokey : cryptographic key management
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 7320 | pgcryptokey | pgcryptokey | 0.85 |
SEC | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| Requires | pgcrypto |
| See Also | pgsodium column_encrypt supabase_vault pg_enigma pg_tde pgcrypto shacrypt cryptint pguecc pgsmcrypto |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.85 |
18 17 16 15 14 | pgcryptokey |
pgcrypto |
| RPM | PIGSTY | 0.85 |
18 17 16 15 14 | pgcryptokey_$v |
- |
| DEB | PIGSTY | 0.85 |
18 17 16 15 14 | postgresql-$v-pgcryptokey |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 |
| el8.aarch64 | PIGSTY 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 |
| el9.x86_64 | PIGSTY 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 |
| el9.aarch64 | PIGSTY 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 |
| el10.x86_64 | PIGSTY 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 |
| el10.aarch64 | PIGSTY 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 | PGDG 0.85 |
| d12.x86_64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| d12.aarch64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| d13.x86_64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| d13.aarch64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| u22.x86_64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| u22.aarch64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| u24.x86_64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| u24.aarch64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| u26.x86_64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
| u26.aarch64 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 | PIGSTY 0.85 |
Source
momjian.us/download/pgcryptokey/
pgcryptokey-0.85.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
pgcryptokey manages encryption data keys wrapped by an access password. It stores wrapped keys in a database table and integrates with pgcrypto for encryption, key rotation and re-encryption.
Install and Unlock
The dependency is pgcrypto. Source release 0.85 uses SQL extension version 1.0 and needs superuser installation. In client mode, first establish the documented session access password using get_shared_key() and set_session_access_password(encrypted_password). The shared-key exchange supports SSL or Unix-domain socket connections only; the encrypted password argument is hex-encoded.
Boot mode instead preloads pgcryptokey_acpass, runs the protected server-side password acquisition script and requires a restart. It makes the access password server-wide and read-only. Choose one mode; boot and client modes cannot be combined while the server is running.
Create and Use a Key
After unlocking access to the keys:
The key length is in bytes. Keys may be selected by name or integer key ID; name lookup refers to an active, non-superseded key.
Rotate and Re-encrypt
supersede_cryptokey(name, byte_len) or its key-ID overload creates a replacement and returns its ID. The old and new keys initially use the same access password. Use the integer key-ID overload change_key_access_password(key_id, new_encrypted_password) to change that wrapping password. The session must already have its shared key and current access password set; the new password must be encrypted with the shared key and hex-encoded.
In source release 0.85, the name overload calls an undefined change_access_password function and cannot complete the password change. Use the integer overload above.
reencrypt_data(data, old_key_id, new_key_id) and reencrypt_data_bytea(data, old_key_id, new_key_id) migrate encrypted values. Preserve old key IDs alongside ciphertext and verify re-encryption before calling drop_cryptokey(name) or its key-ID overload; removing a key can make remaining ciphertext unreadable.
Security Boundary
Protect the key table, function grants, access-password acquisition script and backups. Upstream warns that all users can view the boot-time pgcryptokey.access_password; table privileges are still required to use wrapped keys. get_cryptokey(name) returns raw key material, so do not expose its result through ordinary queries, logs or application traces. This design does not isolate keys from a trusted database administrator.