Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I am looking for the bit flags to detect the file is password-protected, not a regular .zip or .rar.
.zip
.rar
You can use zipinfo and unrar to test whether a ZIP file is encrypted. E.g.:
zipinfo -v file.zip |grep 'file security status:\s*encrypted' unrar v -p- file.rar 2>&1|grep 'Encrypted file'
You can read about the header structure of rar here
And about the zip header structure here
It helps to download the source code of opensource unpackers to read some code examples.