3

Possible Duplicate:
Create an encrypted zip archive with PHP

How to create zipped file with 256 bits encryption using PHP

If there is any example it'll be great

Community
  • 1
  • 1
user1272589
  • 789
  • 1
  • 10
  • 25
  • @mario this solution valid only on windows :( – user1272589 Nov 20 '12 at 23:01
  • You didn't read it carefully enough then. It works on Linux per default. Doesn't answer your question about AES256 though. – mario Nov 20 '12 at 23:02
  • i think what i found that DotNetZip works only on windows. – user1272589 Nov 20 '12 at 23:05
  • The another answer doesn't cover part of 256 bits encryption ... it just a password – user1272589 Nov 20 '12 at 23:08
  • PHP does not have any built-in functions, modules, or PEAR modules that will create an encrypted or password-protected ZIP file. You will need to do this via a OS/software-specific `exec()` command on your server. – Sammitch Nov 20 '12 at 23:17
  • I asked a similar question somewhat recently, please see the reply here: http://stackoverflow.com/questions/7842851/send-encrypted-file-zip-or-txt-via-php-openable-on-windows-pc And another similar reply: http://stackoverflow.com/questions/646195/create-an-encrypted-zip-archive-with-php I came to the conclusion that it was not worth getting an external library/program to do what I wanted to do. Instead, I settled for a password-protected zip file (which is fairly week, as you'll read in the link)... and, for text, implementing strong encryption (see the first link for that one). – Shackrock Nov 20 '12 at 22:56
  • Hi. This is not actually a duplicate question. The linked to question asks for ANY method of encryption, and there is a known bad option for zip based encryption. This question is asking specifically about AES encryption, which is the secure method. In any case, native support is coming in php 7.2 https://stackoverflow.com/a/47589645/144364 – ftrotter Dec 01 '17 at 09:57

2 Answers2

6

On Linux you can use 7zip to create AES encrypted zip files:

exec("7z a -p$PASSWORD -mem=AES256 -tzip $ZIP $SOURCE");

Courtesy of Nfabio from http://ubuntuforums.org/archive/index.php/t-1694923.html

Be sure to apply escapeshellarg().

Note: While this approach will work, but it is better not to call out to the shell with an embedded password. As of php 7.2, this will no longer be necessary because php now natively supports AES zip encryption.

ftrotter
  • 3,066
  • 2
  • 38
  • 52
mario
  • 144,265
  • 20
  • 237
  • 291
0

As I remember, PHP zip classes(I saw)/extension don't support encryption, so for a portable solution I suggest you to:

Community
  • 1
  • 1
SIFE
  • 5,567
  • 7
  • 32
  • 46