【问题标题】:How to check if encrypted Zip archive in PHP?如何检查 PHP 中是否加密的 Zip 存档?
【发布时间】:2012-08-22 21:42:51
【问题描述】:

据我了解,状态是存档加密包含通用位标志。我尝试使用 ZipArchive::statname() 进行检查,但似乎无法通过此方法获取信息。

我还能做什么?阅读存档并解析标题?我知道我可以调用system(),但是我不想使用这个方法,因为它的特殊性(有些托管这个函数被禁用了)。

【问题讨论】:

  • 您对 ZipArchive::statname 进行了哪些尝试?您收到错误消息吗?请提供更多信息。
  • ZipArchive 打开加密文件,但提供的信息不足。方法ZipArchive::statIndex() 的返回值的example。我尝试通过comp_method 识别加密存档,但没有发现依赖。
  • Ticksy 我什至为你做了简单的功能

标签: php encryption zip zipfile ziparchive


【解决方案1】:

ZIP 文件头:(加密文件 vs 普通文件)

09 好像是加密标志。

检查第7个字节是0x09

function zip_is_encrypted($filename) {
  $handle = fopen($filename, "rb");
  $contents = fread($handle, 7);
  fclose($handle);
  return $contents[6] == 0x09;
}

【讨论】:

  • +1 参考一些指定位的官方文档会很好
  • @owlstead standard。关于加密:4.4.4 general purpose bit flag: (2 bytes) Bit 0: If set, indicates that the file is encrypted.
  • @owlstead 您需要检查第 7 个字节的 FIRST BIT。
  • 彼得回答不起作用。不同的 zip 应用程序将不同的信息放在文件的顶部。例如,带有密码的 Izarc 4.3 zip 文件在第 7 个字节上的值为 03,如果没有密码保护,则为 02。
【解决方案2】:

这是 ZIP 标准:http://www.pkware.com/documents/casestudies/APPNOTE.TXT

从第 4.3.7 节开始:

4.3.7  Local file header:

  local file header signature     4 bytes  (0x04034b50)
  version needed to extract       2 bytes
  general purpose bit flag        2 bytes
  compression method              2 bytes
  ...

从第 4.4.4 节开始:

4.4.4 general purpose bit flag: (2 bytes)

    Bit 0: If set, indicates that the file is encrypted.
    ...

所以你需要检查第七个字节的第一个位而不是整个字节。您必须检查每个文件,因为每个文件都可以单独加密(第 4.3.6 节)。

【讨论】:

    【解决方案3】:

    这是行不通的,因为 Header 可以重复 n 次。

    要解决此问题,请打开 zip zip_open() 并尝试读取每个条目 zip_entry_open()

    如果有不可读的条目,则可以对 zip 进行加密!

    【讨论】:

      猜你喜欢
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-26
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多