在 PHP 中加密和解密 Word docx 文件时出现问题


Issue with encrypt and decrypt a word docx file in php

我尝试使用php mcrypt TripleDES对docx格式文件进行加密。

当我尝试解密文件时,出现如下错误。

无法打开 Office Open XML 文件file_name因为存在 内容有问题。

这是下面的代码

function Encrypt($source,$key,$iv) {
      $cipher = mcrypt_module_open(MCRYPT_3DES, '', 'cbc', '');
      mcrypt_generic_init($cipher, $key, $iv);
      $result = mcrypt_generic($cipher, $source);
      mcrypt_generic_deinit($cipher);
      return $result;
}

function Decrypt($source,$key,$iv) {
  $cipher = mcrypt_module_open(MCRYPT_3DES, '', 'cbc', ''); 
  mcrypt_generic_init($cipher, $key, $iv);
  $result = mdecrypt_generic($cipher, $source);
  mcrypt_generic_deinit($cipher);
  return $result;
}

任何帮助将不胜感激。

我已经等待解决方案4个多月了。最后,我在谷歌中找到了一些有价值的答案。现在我已经使用以下链接修复了它。

http://www.howwhywhat.in/how-to-implement-common-file-encryption-and-decryption-between-c-and-php/

最好的部分是,它也有现场示例:)