postgresql_16:9.6.28.4 Raw Encryption Functions
PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > pgcrypto — cryptographic functions > Raw Encryption Functions
These functions only run a cipher over data; they don't have any advanced features of PGP encryption. Therefore they have some major problems:
1. They use user key directly as cipher key. 2. They don't provide any integrity checking, to see if the encrypted data was modified. 3. They expect that users manage all encryption parameters themselves, even IV. 4. They don't handle text.
So, with the introduction of PGP encryption, usage of raw encryption functions is discouraged.
encrypt(data bytea, key bytea, type text) returns bytea decrypt(data bytea, key bytea, type text) returns bytea encrypt_iv(data bytea, key bytea, iv bytea, type text) returns bytea decrypt_iv(data bytea, key bytea, iv bytea, type text) returns bytea
Encrypt/decrypt data using the cipher method specified by type. The syntax of the type string is: *algorithm* - *mode* /pad: *padding* where *algorithm* is one of: bf — Blowfish aes — AES (Rijndael-128, -192 or -256) and *mode* is one of: cbc — next block depends on previous (default) ecb — each block is encrypted separately (for testing only) and *padding* is one of: pkcs — data may be any length (default) none — data must be multiple of cipher block size
So, for example, these are equivalent: encrypt(data, 'fooz', 'bf') encrypt(data, 'fooz', 'bf-cbc/pad:pkcs')
In encrypt_iv and decrypt_iv, the iv parameter is the initial value for the CBC mode; it is ignored for ECB. It is clipped or padded with zeroes if not exactly block size. It defaults to all zeroes in the functions without this parameter.