[fpc-pascal] Saving and reading TBlowfish crypted text

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Tue Mar 17 22:32:05 CET 2015


On 2015-03-17 18:49, Ewald wrote:
> The docs state that it is called automatically upon destruction:

Correct, and I knew that. But I was explicitly looking at the code
Antonio supplied. As I also mentioned, I normally use Read() and
Write(), where he uses different methods.

So looking at his code.

1)   en.WriteAnsiString(Memo1.Lines.Text);
2)   fs.WriteBuffer(Pointer(s1.DataString)^, length(s1.DataString));
3)   en.Free;


1 - Clear text is sent to the encryption object. Internally I presume
    the Read() and Write() methods are used.

2 - The data (bytes) already encrypted are written to the file on the
    hard drive.

3 - The encryption object is freed, which internally calls Flush(), at
    which point the remaining bytes are processed.  But, as far as I
    can see the encrypted data was already written the hard drive
    (in step 2), so that last few bytes Flush() processed are missed.

    So my suggestion is to call Flush() between steps 1 and 2.

This is my interpretation of what is going on with the code I have seen
(I haven't actually tried to compiler and run that code). If I am wrong,
feel free to correct me.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/



More information about the fpc-pascal mailing list