Problems with decrypting an encrypted string from a Postgres table

The example below works with no errors,

However if the string s comes from a database table I get an -208 error.

Is the string “tweaked” in some way when the encrypted string is saved to a database?

Procedure TForm1.Button1Click(Sender: TObject);
var
s, t : string;
begin
s:='This is a test';
t:=AESEncryption1.encrypt(s);
showmessage(t);
s:=AESEncryption1.decrypt(t); // Error -208 if from a Postgres table (saved as a string)
showmessage(s);
end;

Hi,

The string is not “tweaked” in any way, but the BD storage may force some conversion and characters may be incorrectly interpreted. ASCII characters beyond value 127 may cause problem and may be recoded, then breaking the crypto (this is frequent with unicode characters).

If possible, store encrypted strings in hex (noUni) and convert back to ‘raw’, before decryption.

Regards,

bernard

Hi

“If possible, store encrypted strings in hex (noUni) and convert back to ‘raw’, before decryption.”

How can I do that?

Can I just encrypt with Unicode=yesUni and decrypt with Unicode=noUni?

Kind regards,

Ole

before you encrypt.

then, before you decrypt:

var

conv: TConvert;

s, t: string;

begin

conv.TConvert.Create(‘hexa’);

s := conv.FormatToChar(yourEncryptedString);

AESEncryption1.inputFormat := raw;

AESEncryption1.outputFormat := raw;

t := AESEncryption1.Decrypt(s);

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.