Yeoh Ray Mond wrote: >Given what I've seen re the requirement to pass the CRC32 of the 'file' to the >zip writer before compressing and encrypting a 'file', I would guess that it's >impossible to also encrypt a stream that's passed block my block, as happens >in my case. Only if you use the PK ZIP 2.0 encryption. This encryption algorithm uses the CRC32 value of all data for its initialization. With WinZip AES encryption (TDIZipWriter.EncryptionMethod = emWinZipAes128), you can write your archive block by block just as you would do without encryption. Attached is a simple project to demonstrate how this works. >Is that true? Does that requirement also apply to encrypting streams in the >zip64 format? I did not look into the Zip64 format, but given that the CRC32 restriction does not apply to WinZip AES encryption in standard format I expect no different for Zip64. Ralf //------------------------------------------------------------------------------ program DIZipWriter_EncryptMultiple_AES; {$I DI.inc} {$APPTYPE Console} uses {$IFDEF FastMM}FastMM4, {$ENDIF}SysUtils, DIZipWriter; var FileName: string = ''; s1: AnsiString = ''; s2: AnsiString = ''; ZipWriter: TDIZipWriter; begin FileName := ExtractFilePath(ParamStr(0)) + 'test_aes.zip'; s1 := 'This is a first string'; s2 := ' which is followed by a 2nd string.'; ZipWriter := TDIZipWriter.Create{$IFNDEF DI_No_ZipWriter_Component}(nil){$ENDIF}; // Enabl WinZip AES encryption and set the password. ZipWriter.EncryptionMethod := emWinZipAes128; ZipWriter.Password := 'password'; // Create a new Zip file in the temp folder. ZipWriter.NewZipFile(FileName); // Pass the Crc32 value to the new Zip entry. ZipWriter.AddEntry('TwoStrings.txt'); // Write the two AnsiStrings, one at a time. ZipWriter.WriteStrA(s1); ZipWriter.WriteStrA(s2); // Close the Zip entry, finish the Zip archive and close the file on disk. ZipWriter.Free; end.
program DIZipWriter_EncryptMultiple_AES; {$I DI.inc} {$APPTYPE Console} uses {$IFDEF FastMM}FastMM4, {$ENDIF}SysUtils, DIZipWriter; var FileName: string = ''; s1: AnsiString = ''; s2: AnsiString = ''; ZipWriter: TDIZipWriter; begin FileName := ExtractFilePath(ParamStr(0)) + 'test_aes.zip'; s1 := 'This is a first string'; s2 := ' which is followed by a 2nd string.'; ZipWriter := TDIZipWriter.Create{$IFNDEF DI_No_ZipWriter_Component}(nil){$ENDIF}; // Enabl WinZip AES encryption and set the password. ZipWriter.EncryptionMethod := emWinZipAes128; ZipWriter.Password := 'password'; // Create a new Zip file in the temp folder. ZipWriter.NewZipFile(FileName); // Pass the Crc32 value to the new Zip entry. ZipWriter.AddEntry('TwoStrings.txt'); // Write the two AnsiStrings, one at a time. ZipWriter.WriteStrA(s1); ZipWriter.WriteStrA(s2); // Close the Zip entry, finish the Zip archive and close the file on disk. ZipWriter.Free; end.