shacrypt

Implements SHA256-CRYPT and SHA512-CRYPT password encryption schemes

Overview

PackageVersionCategoryLicenseLanguage
shacrypt1.1UTILPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4440shacryptNoYesNoYesNoYes-
Relatedhashlib xxhash cryptint pguecc pgcrypto gzip bzip zstd

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.11817161514shacrypt-
RPMPIGSTY1.11817161514shacrypt_$v-
DEBPIGSTY1.11817161514postgresql-$v-shacrypt-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
d13.x86_64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
d13.aarch64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
u22.x86_64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
u22.aarch64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
u24.x86_64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
u24.aarch64
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1
PIGSTY 1.1

Build

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

pig build pkg shacrypt         # build RPM / DEB packages

Install

You can install shacrypt 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 shacrypt;          # Install for current active PG version
pig ext install -y shacrypt -v 18  # PG 18
pig ext install -y shacrypt -v 17  # PG 17
pig ext install -y shacrypt -v 16  # PG 16
pig ext install -y shacrypt -v 15  # PG 15
pig ext install -y shacrypt -v 14  # PG 14
dnf install -y shacrypt_18       # PG 18
dnf install -y shacrypt_17       # PG 17
dnf install -y shacrypt_16       # PG 16
dnf install -y shacrypt_15       # PG 15
dnf install -y shacrypt_14       # PG 14
apt install -y postgresql-18-shacrypt   # PG 18
apt install -y postgresql-17-shacrypt   # PG 17
apt install -y postgresql-16-shacrypt   # PG 16
apt install -y postgresql-15-shacrypt   # PG 15
apt install -y postgresql-14-shacrypt   # PG 14

Create Extension:

CREATE EXTENSION shacrypt;

Usage

shacrypt: SHA-crypt password hashing for PostgreSQL

Generate SHA256-CRYPT and SHA512-CRYPT password hashes per the SHA-crypt specification.

Functions

sha256_crypt(key text, salt text) RETURNS text

SELECT sha256_crypt('clearpassword', 'somesalt');
-- $5$somesalt$l3SlbI688JBlRS9RWFC1EwZLNJqfQKcrF3yhcbc7ffA

With custom rounds:

SELECT sha256_crypt('clearpassword', '$5$rounds=10000$somesalt');
-- $5$rounds=10000$somesalt$OekH6Tu7EOJIAvxKJ4Ko4bG0DxgO83gZODJLTTjXJi5

sha512_crypt(key text, salt text) RETURNS text

SELECT sha512_crypt('clearpassword', 'somesalt');
-- $6$somesalt$dDcgWMHOtvHI6qT/Khi3uaaxXN6v4N9bnOeWFl/Y6K3pzxi/...

Salt Format

  • Simple salt: 'somesalt'
  • With algorithm prefix: '$5$somesalt' (SHA-256) or '$6$somesalt' (SHA-512)
  • With custom rounds: '$5$rounds=10000$somesalt'

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