Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check .7z is encrypted #42

Closed
yangyu2010 opened this issue Oct 24, 2019 · 3 comments
Closed

check .7z is encrypted #42

yangyu2010 opened this issue Oct 24, 2019 · 3 comments

Comments

@yangyu2010
Copy link

how can I check .7z file has encrypted.
I try this way

var items = [LzmaSDKObjCItem]()
        reader.iterate { (item: LzmaSDKObjCItem, error: Error?) -> Bool in
            print(item.isEncrypted)
            items.append(item)
            return true
        }

but its not work,
the item cannot be read because the password is incorrect.
So I want to make sure that the file has a password, and if it does, I'll prompt the user for a password
Hope to get your answer

@OlehKulykov
Copy link
Owner

OlehKulykov commented Oct 27, 2019

Hi,
the quick answer is to listen password callback and forget about sure that the file has a password.
Because, the internal logic will ask user/user code for the password when it's needed and if it's needed.
Otherwise, the whole concept of password protected archive is gone when it's written/stored somehow inside the file :)
Also, keep in mind that archived may have encrypted header, i.e. the list of file, so you can't even see the list of files before first access.
For the reference, how the encrypted archives works, you can check the behavior the console 7za utility to check when the logic prompts the password, i.e. never, before opening and listing the file content or before extracting the first file.

So, if behavior of the archiver is not fits for your needs, just do not use such logic to avoid wrong app architecture.

Or, open archive and extract items in a separate thread and when the original SDK will ask the password, suspend an execution thread, display password prompt in a UI thread and then resume execution thread with user provided password.

@yangyu2010
Copy link
Author

@OlehKulykov
Hi,
Thank you for your detailed explanation.I understand what you mean, thank you very much.
I have another question I would like to ask you.If you like, I am very happy to know your thoughts.

My need is to compress large files. Use 7z volume archive.
For example, I have a 100 MB file and want to break it down into two 7z files.
My idea is to convert the file to NSData. Then use 7z compression.

- (BOOL) addData:(nonnull NSData *) data forPath:(nonnull NSString *) path;

I look forward to your answer.

@OlehKulykov
Copy link
Owner

Hi,
unfortunately split handler is not ported and was not even planned for a mobile platform, due to multiple write output and reader input. But thanks for the good idea, I'll keep in mind...
So, in this case I would like to recommend to:

  1. Archive single big file and then split output 7z file into few small parts.
  2. Read single big file into few small NSData's and archive each part individually into few 7z's archives.

P.S.: for a big input files, it's better to use - (BOOL) addPath:(nonnull NSString *) aPath forPath:(nonnull NSString *) path; method instead of keeping all in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants