archive icon indicating copy to clipboard operation
archive copied to clipboard

How do I check whether zip file is password protected?

Open imoreapps opened this issue 2 years ago • 2 comments

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.

imoreapps avatar Apr 21 '23 09:04 imoreapps

Unfortunately there isn't a good (any) way currently.

brendan-duncan avatar Apr 21 '23 16:04 brendan-duncan

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();
  }
}

imoreapps avatar Apr 22 '23 10:04 imoreapps