Jump to content
PeterPanettone

Extract from encrypted ZIP?

Recommended Posts

While Delphi 12 supports ZIP encryption, the actual encryption algorithm has to be provided by the developer itself or a library implementing the new IZipCryptor interface.

 

For the common PKWARE Zip 2.0 encryption (see APPNOTE.TXT) an implementation can be found in PKWAREZipCryptor.pas. The usage is shown in the following example, which extracts all files from an encrypted zip file:

var
  bytes: TBytes;
  fileName: string;
  zipFile: TZipFile;
begin
  zipFile := TZipFile.Create;
  try
    zipFile.Cryptor := TPKWAREZipCryptor.Create;
    zipFile.Password := cPassword;
    zipFile.Open(zipFileName, zmRead);
    for var I := 0 to zipfile.FileCount - 1 do begin
      fileName := zipFile.FileNames[I];
      zipFile.Read(I, bytes);
      TFile.WriteAllBytes(fileName, bytes);
    end;
    zipFile.Close;
  finally
    zipFile.Free;
  end;
end;

 

  • Like 3
  • Thanks 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×