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;
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.
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);