encryptiontclientdatasetdelphi-10.4-sydneylockbox-3

ClientDatSet.LoadFromFile(DeCryptFile(XMLFile))?


I have a Delphi 10.4 program with a clientdataset, loading XML files users choose with OpenFile dialog. It works just fine and depending on the contents of the XML, the fielddef structure is set automatically.

Now I want to be able to read Decrypted files and with ClientDataSet.SaveToFile, save Encrypted files.

Currently I'm using Lockbox 3.7 to Decrypt the chosen file, creating a temp file, which is then read by loadfromfile. Likewise Savetofile writes data back to a temp file, which is then encrypted and given it's chosen name. It works very well, but leaves the temp file on disk. And even if I delete the temp file in code, it's relatively easy to recover it, if you know how. So the security with Encryption like this, is not so high after all.

I would want to be able to perform the decryption directly in LoadFromFile (and similar encryption at SaveToFile) as a fileEn(or De)Crypt function, as suggested by the subject, without the use of temp files, but haven't been able to find any useful functions.

Do anybody know of such function ? If so, please point me in the right direction. The last couple of days I've been using google to search for something useful, but it has left me more confused and lost, than I feel I was before.

An alternative solution where the temp files created by the LockBox EnCryptFile (and DeCryptFile) are completely destroyed, to a point where no recovery is possible, would do as a temporary solution, so pointers to ways to destroy a file completely, would also be welcome.

Thanks in advance for any help I can get.


Solution

  • Use ClientDataSet.LoadFromStream instead of LoadFromFile. I'm sure LockBox has a function to decrypt into a TStream. Use a TMemoryStream to avoid storing decrypted data to disk.

    Likewise, write the client dataset to a stream (SaveToStream), use a TMemoryStream and it will stay in memory. Then encrypt it and save the result to disk.