有没有办法检查 zip 文件是否受密码保护?

ine*_*elp 2 linux bash shell zip

我正在编写一个 bash 脚本,它使用 zip 压缩(加密或不加密,具体取决于用户选择)和解压缩文件。我的问题是解压部分 - 当用户选择要解压的 zip 文件(通过 zenity 文件选择)时,是否有任何方法可以检查该文件是否受密码保护,以便询问用户密码(或者是否受密码保护) t,继续解压缩文件)?

我还没有真正尝试过任何事情,因为我一直在努力想出任何想法或在堆栈和其他网站上找到解决方案。

Cyr*_*rus 6

if 7z l -slt file.zip | grep -q ZipCrypto; then
  echo "password protected / encrypted"
else
  echo "no password protection / not encrypted"
fi
Run Code Online (Sandbox Code Playgroud)

请参阅:如何检测 zip 文件加密算法