【问题标题】:How to open / decrypt a password protected word-file (docx) with PHP如何使用 PHP 打开/解密受密码保护的 word 文件 (docx)
【发布时间】:2018-07-25 07:12:44
【问题描述】:

我正在尝试使用 PHP 以编程方式打开一个 word 文件 (.docx)。此 word 文件受密码保护和加密,因此如果不提供密码,则无法显示其内容。我当然知道密码。

但是我怎样才能通过提供密码来使用 PHP 打开这个 word 文件呢?

唯一至少提到密码保护的 PHP 库是伟大的 PhpOffice/PhpWord - 但它不支持打开受密码保护的文件:https://github.com/PHPOffice/PHPWord/issues/357

请注意,密码保护以防止不必要的更改与 - 这是我的情况 - 防止未经授权的打开之间存在细微差别。

TIA

【问题讨论】:

  • 您指的是“信息权限管理服务”还是可用的简单“限制格式”选项,包括使用密码......或其他技术?
  • @RamRaider - docx 文件只有在提供密码后才能打开。这不是关于限制格式,而是关于打开文档。我不知道该技术的正确术语,但我认为它是“IRMS”。
  • 不,这听起来像是标准的文件密码保护,而不是 IRMS。在 Word 对象模型中,这将是 Documents.Open 方法的 Password 参数。但如果 PHP 仅适用于 ZIP 包和 Office Open XML 文件格式,则它不能用于“打开”受密码保护的加密文件。这些是二进制格式,而不是 Open XML。
  • 我有点困惑。我会假设它在 Word 对象模型中,因为我可以在例如打开它。带有提到的密码参数的 VBA: Documents.Open(filePath, PasswordDocument:=password) (但我还必须补充一点,我对这个主题没有更深入的了解,因此非常感谢任何更改标题或问题的建议:) )

标签: php encryption ms-word passwords docx


【解决方案1】:

欢迎您查看我的PHPDecryptXLSXWithPassword repo。

先用密码解密文件,再用PHPWord解密文件。

这是一个例子:

require_once('PHPDecryptXLSXWithPassword.php');

$encryptedFilePath = '../path/to/encrypted/file.docx';
$password = 'mypassword'; // password to "open" the file
$decryptedFilePath = '../path/to/decrypted/file.docx';

decrypt($encryptedFilePath, $password, $decryptedFilePath);

// now you can use PHPWord with $decryptedFilePath

注意:这是一个实验性代码,请谨慎使用。不要在生产中使用!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 2020-08-29
    • 1970-01-01
    • 2013-10-27
    • 2021-03-28
    相关资源
    最近更新 更多