i have an error saving (savetofile) an encrypted text and try to decrypt the same text using loadfromfile.
The code is simple:
var
se : string;
st : TStringList;
begin
st := TStringList.Create;
se := AES.Encrypt('test');
st.Add( se );
st.SaveToFile( 'c:\Temp\CONN.CFG' );
st.Clear;
st.LoadFromFile( 'c:\Temp\CONN.CFG' );
AES.Decrypt( st[ 0 ] ); // <<< Error
end;
I am using the component's default property values.
Hi, if you used the default setting, the outputFormat is set to raw.
This means that some characters may not be ASCII and SaveToFile/LoadFromFile need to be told what type of strings they manipulate.
st.SaveToFile( 'c:\Temp\CONN.CFG' , TEncoding.UTF8); // may help - to be tested.
On a general note, I don't recommend using these functions with encrypted strings. It is better to use FileWrite/FileRead.
Another option is to set outputFormat to 'hexa' or 'base64', but in this case, you need to convert the strings back to 'raw' before decrypting, with a TConvert.