I am using the following definition for the postgres functions:
DROP FUNCTION IF EXISTS EncryptStringWithIV(text);
create or replace function EncryptStringWithIV(email text) returns bytea as '
declare
Key text;
IV text;
value bytea;
begin
select sStringValue into Key from XtkOption where sName=''Key'';
select sStringValue into IV from XtkOption where sName=''IV'';
value = encrypt_iv($1::bytea, Key::bytea, IV::bytea, ''aes'');
return value;
end;
' language plpgsql
;
DROP FUNCTION IF EXISTS DecryptStringWithIV(bytea);
create or replace function DecryptStringWithIV(email bytea) returns bytea as '
declare
Key text;
IV text;
value bytea;
begin
select sStringValue into Key from XtkOption where sName=''Key'';
select sStringValue into IV from XtkOption where sName=''IV'';
value = $1;
return decrypt_iv(value, Key::bytea, IV::bytea, ''aes'');
end;
' language plpgsql
;
This is my output when the fn. is called :
EncryptStringWithIV('123') - \x8dd75f487a7b45e73fbe365545f0506a
DecryptStringWithIV('\\x8dd75f487a7b45e73fbe365545f0506a') - \x313233
Should I be converting the output format to get back the exact text value (123)? I am not able to figure out where exactly I am going wrong. any help would be greatly appreciated. Thanks.
byteaand the default way of display such a "blob" is hex encoded in Postgres. If you want a proper number, then change your code to return a proper number, not some binary value