2

SynCrypto is an open source data encryption library for Delphi and FPC included in SynPDF.

I use this code for file encryption:

var
  inputfile : RawByteString;
  outputfile: RawByteString;
begin
  inputfile := StringFromFile('c:\test1.mp4');
  outputfile := TAESCFB.SimpleEncrypt(inputfile,'TEST',true,true);
  FileFromString(outputfile,'c:\test2.mp4');
end;

However it doesn't work for large files (>1GB). Is there any way to encrypt large files?

Xel Naga
  • 826
  • 11
  • 28
  • What "doesn't work?" What error are you getting? Where in the code is the error happening? What debugging have you done? – mirtheil Jul 15 '21 at 15:46
  • 4
    Obviously, loading a 1GB file into memory at one time is not a good idea. By the time `FileFromString()` is called, you are using 2+GB of memory. You need to read and encrypt the file in small chunks instead. I was going to suggest using `SimpleEncryptFile()`, until I saw it is doing the exact same thing internally that you are doing, so that is not helpful. So you are just going to have to do the chunking manually, using the appropriate `Encrypt...()` method for each chunk. The `SimpleEncrypt...()` methods are not going to cut it for this large of data. – Remy Lebeau Jul 15 '21 at 16:08
  • 2
    It's a mistake to use strings as your buffer and a mistake to put the entire file in memory. Process the file in chunks as Remy says. – David Heffernan Jul 15 '21 at 18:28
  • Thank you all. I got the point. – Xel Naga Jul 15 '21 at 20:38
  • Search for methods that take a tstream. – Marco van de Voort Jul 18 '21 at 18:58

0 Answers0