In php 7.2.0 I create a zip that is password protected and encrypted per file like suggested in the php docs.
This feature works well and after the zip is downloaded to the client on windows the user is prompted to fill-in a password and the contents are unzipped.
On an OS X machine after double clicking the file an error message will appear, when opening in terminal a clearer error appears:
unsupported compression method 99
Not even prompting for a password, this is not related to the ever expanding zip problem that I have seen around here. It seems that this zip is somehow different than a password protected zip created on another Mac machine.
This has something to do with the encryption method EM_AES_256 which has been introduced by WinZip but not used by others.
class PatientReferralZipController extends Controller{
protected $zip;
protected $zipName = 'verwijsbrief';
public function generateZip($text, $doc, $password, $patient){
$zipPath = config('constants.patient_files_upload_dir')."/".$patient->id;
$this->createZip($password, $zipPath);
$this->addTextToZip($text);
$this->addDocumentToZip($doc);
$this->zip->close();
return $this->zip;
}
public function createZip($password, $zipPath){
if (!file_exists($zipPath)) {
mkdir($zipPath, 0777, true);
}
if($this->zip->open($zipPath."/".$this->zipName.".zip", ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE){
$this->zip->setPassword($password);
}
}
public function addTextToZip($text){
$this->zip->addFromString('verwijsbriefTextvak.txt',$text);
$this->zip->setEncryptionName('verwijsbriefTextvak.txt', ZipArchive::EM_AES_256);
}
public function addDocumentToZip($doc){
$ext = $doc->getClientOriginalExtension();
$filename = $this->zipName.".".$ext;
$this->zip->addFile($doc->path(),$filename);
$this->zip->setEncryptionName($filename, ZipArchive::EM_AES_256);
}
public function __construct($text, $doc, $password, $patient){
$this->zip = new ZipArchive();
$this->generateZip($text, $doc, $password, $patient);
}}
Like I thought it has something to do with WinZip Which uses a proprietary encryption. "WinZip introduced its own AES-256 encryption" - Wikipedia
Related post about un-zipping issues: superuser