Cryptographic functions for PostgreSQL
The pgcrypto
extension provides cryptographic functions for PostgreSQL, including hashing, encryption, and random data generation.
Your Nile database arrives with the pgcrypto extension already enabled.
The pgcrypto extension provides functions for:
The crypt()
function is recommended for password hashing:
✅ Use crypt() with Blowfish:
password_hash = public.crypt(password, public.gen_salt('bf', 8))
❌ Don’t store plain MD5 (unsafe!):
password_hash = public.md5(password)
✅ Store keys securely outside the database: encrypted_data = public.encrypt(data, current_setting('app.encryption_key'), 'aes')
❌ Don’t store keys in the database
❌ Don’t hardcode keys in application code
✅ Generate a new salt for each password: SELECT public.gen_salt('bf', 8);
❌ Don’t reuse salts
❌ Don’t use static salts
Cryptographic functions for PostgreSQL
The pgcrypto
extension provides cryptographic functions for PostgreSQL, including hashing, encryption, and random data generation.
Your Nile database arrives with the pgcrypto extension already enabled.
The pgcrypto extension provides functions for:
The crypt()
function is recommended for password hashing:
✅ Use crypt() with Blowfish:
password_hash = public.crypt(password, public.gen_salt('bf', 8))
❌ Don’t store plain MD5 (unsafe!):
password_hash = public.md5(password)
✅ Store keys securely outside the database: encrypted_data = public.encrypt(data, current_setting('app.encryption_key'), 'aes')
❌ Don’t store keys in the database
❌ Don’t hardcode keys in application code
✅ Generate a new salt for each password: SELECT public.gen_salt('bf', 8);
❌ Don’t reuse salts
❌ Don’t use static salts