Hrm, while text is certainly interesting, I just hoped that since I could open a file with a string list, it would save the file (once decrypted) the same as when I opened it and 'The End'. Ahwell.
A file is just a collection of raw bytes. A
TStringList is a collection of strings in memory. How you get from bytes to strings requires interpreting the bytes using a charset, which governs how specific bytes are mapped to specific characters. And since
TStringList assumes a file's bytes are textual in nature, that also includes platform-specific line break handling, as some platforms use
CR-only, some use
LF-only, and some use
CR+
LF.
So no, you can't rely on a
TStringList preserving the original file as-is.
I guess I can't encrypt an 'Array[1..1024] of byte;' either, hmm?
Yes, of course you can. Why would you think otherwise?
Since it's an array and not a single 'block'
An
array is always a single block of contiguous memory. For encryption purposes, just make sure to use an element type that is a value type, like
Byte,
Integer, etc, and not a reference type, like
String,
TObject,
Pointer, etc.
If you declare it as: packed array [1..1024] of byte it should ocupy exactly 1024 consecutive bytes on any platform.
You don't need the
packed for a byte array,
In fact, you could probably pass a String as an array of bytes if you take the simple precaution of casting it and passing it as String[1].
That really depends on whether
String is a
ShortString,
AnsiString, or
UnicodeString. It is not really a good idea to use a
String as a binary buffer.