Functions provided by the Entrust PostgreSQL Extension
-
open_session()
Copyopen_session(access token file path) returns void
open_session(access token) returns voidThe open_session() function is responsible for creating a session. It reads the access token either from a file or directly as a parameter. Once the access token is obtained, the function stores it in cache for subsequent use.
For example:
Copyselect open_session('file:///opt/hcs/etc/psql.conf'); -
close_session()
Copyclose_session() returns voidThe close_session() function is used to close a session. This function will remove the access token and keys from the cache.
For example:
Copyselect close_session(); -
get_key()
Copyget_key(keyname) returns key handle (INTEGER)The get_key() function is used to fetch a key from the Cryptographic Security Platform Vault for Databases. It stores the key in the cache and returns the key handle.
For example:
Copyselect get_key('master-key1') as handle \gset -
encrypt_data(text, key_handle)
Copyencrypt_data(data TEXT, keyhandle INTEGER) returns TEXTThe encrypt_data() function is used to encrypt the provided TEXT type data. It has two parameters: data and key_handle. The key_handle is returned by the get_key() function. It returns encrypted TEXT data.
For example:
Copyinsert into users (name, credit_card_details) values ('John', encrypt_data('my_details', :handle)); -
decrypt_data()
Copydecrypt_data(encrypted_data TEXT) returns TEXTThe decrypt_data() function is used to decrypt TEXT type data. It also verifies the integrity of the data during decryption. It returns decrypted TEXT data.
For example:
Copyselect name, decrypt_data(credit_card_details) from users; -
encrypt_data_bytea()
Copyencrypt_data_bytea(data BYTEA, keyhandle INTEGER) returns BYTEAThe encrypt_data_bytea() function is used to encrypt the provided BYTEA type data. It has two parameters: data and key_handle. The key_handle is returned by the get_key() function. It returns encrypted BYTEA data.
For example:
Copyinsert into users (name, bytea_details) values ('John', encrypt_data_bytea(E'\\xDEADBEEF', :handle)); -
decrypt_data_bytea()
Copydecrypt_data_bytea(encrypted_data BYTEA) returns BYTEAThe decrypt_data_bytea() function is used to decrypt BYTEA data. It also verifies the integrity of the data during decryption. It returns decrypted BYTEA data.
For example:
Copyselect name, decrypt_data_bytea(bytea_details) from users;
