I'm trying to port an Oracle function to Postgres. The purpose of this function is encrypt data using AES-256 algorithm. Since I'm no expert in either Oracle or cryptography I would highly appreciate all possible help. The goal is to get the same encrypted result both in Oracle and Postgres using the same data and key.
The Oracle function is
function encrypt(data varchar2, key raw) return raw as
begin
return dbms_crypto.encrypt(
utl_i18n.string_to_raw(data, 'AL32UTF8'),
dbms_crypto.ENCRYPT_AES256
+ dbms_crypto.CHAIN_CBC
+ dbms_crypto.PAD_PKCS5,
key
);
end;