7-Zip command to create and extract a password-protected ZIP file on Windows?

user3254893 picture user3254893 · Jan 26, 2015 · Viewed 134.7k times · Source

On Mac/Linux to zip/unzip password protected zip files, I use: Zip:

zip -P password -r encrypted.zip folderIWantToZip

Unzip:

unzip -P password encrypted.zip

What are the equivalent command on Windows on the command line (assuming that 7zip has been installed)?

I have been doing research and found that it is not possible to password encrypt using the Java zip4j library. Also Windows does not have a zip command prompt like Mac/Linux

Answer

Gerard Rozsavolgyi picture Gerard Rozsavolgyi · Jan 27, 2015

From http://www.dotnetperls.com:

7z a secure.7z * -pSECRET

Where:

7z        : name and path of 7-Zip executable
a         : add to archive
secure.7z : name of destination archive
*         : add all files from current directory to destination archive
-pSECRET  : specify the password "SECRET"

To open :

7z x secure.7z

Then provide the SECRET password

Note: If the password contains spaces or special characters, then enclose it with single quotes

7z a secure.7z * -p"pa$$word @|"