How do I check whether zip file is password protected?
Opened this issue · 2 comments
imoreapps commented
First of all, thank you for providing such a great Flutter package. As shown in the title, how do I check whether zip file is password protected? Any tips would be appreciated.
brendan-duncan commented
Unfortunately there isn't a good (any) way currently.
imoreapps commented
Unfortunately there isn't a good (any) way currently.
I've stripped a temporary method from the archive package to do this.
bool isZipFileEncrypted(File zipFile) {
final input = InputFileStream(zipFile.path);
try {
final signature = input.readUint32();
if (signature != ZipFile.SIGNATURE) {
throw ArchiveException('Invalid Zip Signature');
}
final version = input.readUint16();
final flags = input.readUint16();
final encryptionType = (flags & 0x1) != 0
? ZipFile.encryptionZipCrypto
: ZipFile.encryptionNone;
return encryptionType != ZipFile.encryptionNone;
} finally {
input.close();
}
}