Reputation: 43
I'm writing a bash script which compresses (with encryption or without, depending on what the user chooses) and decompresses files using zip. My problem is the decompressing part - when the user chooses a zip file to decompress (via zenity file selection), is there any way to check if the file is password protected in order to ask the user for the password (or if it isn't, just proceed and decompress the file)?
I didn't really try anything yet, as I've struggled to come up with any idea or find a solution on stack and other websites.
Upvotes: 2
Views: 8002
Reputation: 325
The best way i found
To always try to set password.
If password not exist set qwerty
7z x -aou /tmp/archive.zip -pqwerty
If encrypted, there must be message
encrypted archive! Wrong password
For additional check i recommend command that print technical info by 7z.
If password not exist set qwerty
7z l -slt /tmp/archive.zip -pqwerty
Output must contain Encrypted = +
or encrypted archive! Wrong password
Upvotes: 0
Reputation: 2175
Also: In a DOS prompt, type "unzip myfile.zip" and if you get prompted for the password, it is protected.
Upvotes: 0
Reputation: 88949
if 7z l -slt file.zip | grep -q ZipCrypto; then
echo "password protected / encrypted"
else
echo "no password protection / not encrypted"
fi
See: How to detect zip file encryption algorithm
Upvotes: 6