Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use unzOpenCurrentFilePassword?

Tags:

unzip

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. */

like image 761
Romeo Avatar asked Dec 22 '25 23:12

Romeo


1 Answers

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
like image 139
Zizaco Avatar answered Dec 31 '25 17:12

Zizaco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!