Romeo
Romeo

Reputation: 21

How to use unzOpenCurrentFilePassword?

Can someone help me port my code from void * uzFile = unzOpen("zip filename");

to use the unzOpenCurrentFilePassword from minizip ? I want to protect my zip file with a password.

I tried many times but I failed using it. Thanks

extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, const char* password)); /* Open for reading data the current file in the zipfile. password is a crypting password If there is no error, the return value is UNZ_OK. */

Upvotes: 2

Views: 3554

Answers (1)

Zizaco
Zizaco

Reputation: 374

Before you compile zlib, remove the definition of NOUNCRYPT in unzip.c. Then "unzOpenCurrentFilePassword will be enabled".

unzip.c Line 72:

#ifndef NOUNCRYPT
    //#define NOUNCRYPT Comment this line, so unzip protected files will be enabled
#endif

Why? Among other things, the definition of NOUNCRYPT causes an absurd return in unzOpenCurrentFilePassword function.

extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
                                        int* level, int raw, const char* password)
[...]

#   ifndef NOUNCRYPT
    char source[12];
#   else
    if (password != NULL)
        return UNZ_PARAMERROR;
#   endif

Upvotes: 11

Related Questions