Reading Password Protected ZIP Archives

Hi All,

I have a series of ZIP Archives which are password protected (it is a common password across all ZIP Archives). Having looked at archive/zip there is no mention of handling password protected archives.

I did find a solution on Stack Overflow, but I would prefer to use a full golang solution. Any thoughts or ideas would be appreciated

There is no support for encrypted zip files in the standard library.

You could file a bug for the missing feature, but I wouldn’t hold your breath on it being implemented.

Meanwhile, I searched for “zip encrypt” and found this package.


Thanks. I checked out the matm/scytale package you mentioned, but unfortunately the compression algorithm used on the file isn’t supported yet. I may try to write support in to support the algorithm and feed it back into the project.

In the meantime, I’ll go with the Stack Overflow solution.

Thanks @adg!

1 Like

For anyone following along – I filed a bug as it appears that *zipFile.Open cannot open AES 256 password encrypted, deflated archives.

I suspect the Stack Overflow solution works as is; but on a Mac, it is easier to use unar. Once you download it (and place it in a directory on your PATH e.g. /usr/bin); replace all mentions in the Stack Overflow of 7za with unar e.g.

commandString := fmt.Sprintf(`unar -f -p %s -o %s %s`, zip_password, extract_path, zip_path)

@alexmcroberts , check out my fork of archive/zip which includes reading (still working on writing) of password protected ZIP files. The package documentation is here.

For the public API I’ve added 2 methods to the File type:

  1. IsEncrypted() bool
  2. SetPassword(password []byte)

An example:

Let me know if you run into any issues.


I can confirm @alexmullins library works very well in this case. +1

@alexmcroberts That’s good to here!

Password protected writing is being worked on atm. I had to change the API a little to unify the reading and writing portions. I’ll post back here when it’s complete.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.