Zip icon indicating copy to clipboard operation
Zip copied to clipboard

Password mismatch wile unzipping

Open sz-ashik440 opened this issue 3 years ago • 11 comments

I have tried to make zip file with password protection. Zip creation succeeded but while unzipping the password is not matching anymore. I have tried to unzip with Finder on macOS Catlina(version 10.15.6) but still no luck.

let url = getDocumentsDirectory().appendingPathComponent("log.txt")
try fileBody.write(to: url, atomically: true, encoding: .utf8)
let zipURL = self.getDocumentsDirectory().appendingPathComponent("log.zip")
try Zip.zipFiles(paths: [url], zipFilePath: zipURL, password: "123", compression: .NoCompression) { (progress) in
print("zip progress: \(progress)")
}

Environment Informations:

Zip: 2.1.1 Swift version: 5.2 Xcode version: 12.2 (12B45b) Tested On: iPhone X(iOS 14.0.1), iPhone 6s Plus(13.4.1)

sz-ashik440 avatar Nov 20 '20 12:11 sz-ashik440

We are also facing the same issue. Environment details are same.

patrasupratim avatar Nov 22 '20 08:11 patrasupratim

same issue😓.

HyunjoonKo avatar Dec 07 '20 07:12 HyunjoonKo

I ended up rewriting the library using SSZipArchive..

patrasupratim avatar Dec 07 '20 08:12 patrasupratim

Hi Patrasupratim, I had the same issue with Zip and I am trying to use SSZIpArchive and I haven't had any luck. I am using swift 5.3 in Xcode 12. Do you have a sample code using SSZipArchive for me to look at or the exact steps to follow to make it work.

Thanks,

Much appreciated

ajc-1924 avatar Dec 13 '20 07:12 ajc-1924

@ajc-1924 check this issue on SSZipArchive https://github.com/ZipArchive/ZipArchive/issues/601

sz-ashik440 avatar Dec 13 '20 07:12 sz-ashik440

Hi @ajc-1924,

@sz-ashik440 pointed it right. It needs to disable the default AES encryption from other overloaded methods. Link is here - https://github.com/ZipArchive/ZipArchive/issues/601#issuecomment-731170085.

patrasupratim avatar Dec 13 '20 12:12 patrasupratim

Thank you @patrasupratim and @sz-ashik440 for your replay. However, I still cannot unzip the file using SSZipArchive. I am using swift 5.3, xocde 12. I am using the emulator. the file I am trying to unzip is password protected. this file gets unzipped properly in linux, windows as well as mac when I double click on the file it the default archive application tries to open ti. it prompts me for the password, I enter it and it gets successfully unzipped. the file was zipped using AES encryption.

this is the call to the unzip method:

let success: Bool = SSZipArchive.unzipFile(atPath: srcURL.path, toDestination: destURL.path, preserveAttributes: true, overwrite: true, nestedZipLevel: 1, password: !password.isEmpty ? password : nil, error: nil, delegate: nil, progressHandler: nil, completionHandler: nil)

and it fails here:

switch (zip->file_info.compression_method) { case MZ_COMPRESS_METHOD_STORE: case MZ_COMPRESS_METHOD_DEFLATE: #ifdef HAVE_BZIP2 case MZ_COMPRESS_METHOD_BZIP2: #endif #ifdef HAVE_LZMA case MZ_COMPRESS_METHOD_LZMA: #endif err = MZ_OK; break; default: return MZ_SUPPORT_ERROR; }

I returns MZ_SUPPORT_ERROR

I Have been trying to make this work for days now with no luck.

I appreciate any help anyone can give me. I am trying to learn Swift.

ajc-1924 avatar Dec 17 '20 22:12 ajc-1924

Hi @ajc-1924,

I used following code for zipping the file - let success = SSZipArchive.createZipFile(atPath: zipUrl.path, withContentsOfDirectory: stagingDirUrl.path, keepParentDirectory: false, compressionLevel: zlib.Z_BEST_COMPRESSION, password: password, aes: false, progressHandler: nil) This way I can unzip the compressed file in mac and windows as well. The thing is if the file is protected using AES, then there is need an unzip application written using the same library. Can you please try using aes: false.

patrasupratim avatar Dec 18 '20 03:12 patrasupratim

Thank you again @patrasupratim and @sz-ashik440, the things is I do not have controlled over the zipped file. I just need to unzip it. I know the zipped file is password is password protected and it was protected using the AES method. It can be unzipped on linux and windows using java libraries as well as 7zip and on mac it can be unzipped using the default unzip application. I need to unzip it using swift 5.3 using xcode 12 on ios. regards, I appreciate your input.

ajc-1924 avatar Dec 19 '20 00:12 ajc-1924

Any news on this issue... I don't know if disabling AES when zipping using this library could help... Thanks in advance.

klauslanza avatar Apr 09 '21 10:04 klauslanza

same issue😓.

Marcello168 avatar May 16 '22 03:05 Marcello168