Issue with encrypt and decrypt a word docx file in php

孤街浪徒 提交于 2020-01-30 06:58:04

问题


I tried to use php mcrypt TripleDES for encryption for docx format files.

When i tried to decrypt the file, i am getting the error as follows.

The Office Open XML file file_name cannot be opened because there are problems with the contents.

Here is the below code

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

Any help will be appreciated.


回答1:


I have been waiting for the solution more than 4 months. Finally i found some valuable answer in google. Now i have fixed it by using below link.

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

Best part is ,it has live examples too:)



来源:https://stackoverflow.com/questions/10548386/issue-with-encrypt-and-decrypt-a-word-docx-file-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!