C zip library that can create password protected zip files in Windows?

Does anyone know a C library that can create password protected ZIP files on Windows? It seems that the password protection option for zip files with the built-in zip utility has been removed from windows 7, but I don't think this is a problem.

Can zziplib or 7-zip sdk do this?

+8
c ++ c windows windows-7 zip
source share
3 answers

7-Zip SDK (LZMA SDK) supports archive with password protection.

Related SO post:
https://stackoverflow.com/questions/221049/how-secure-is-7-zip

LZMA SDK:
http://www.7-zip.org/sdk.html

+2
source share

If you can use .NET, check out DotNetZip: http://dotnetzip.codeplex.com/

C ++ .NET example for creating a password-protected ZIP: http://cheeso.members.winisp.net/DotNetZipHelp/Code%20Examples/Cpp.htm

+1
source share

MINIZIP + zlib supports AES 256 encryption and is very easy to use!

Code based on minizip unzip.c. include stdio.h zip.h unzip.h

First create a zip with a file inside with a password. The zip file must be in the same directory as the executable file. Run the program from the prompt in the generated program directory. In this example, only the first file is retrieved!

/*-----------start-------------- */ /*Tries to open the zip in the current directory.*/ unzFile zfile = unzOpen("teste.zip"); if(zfile==NULL) { printf("Error!"); return; } printf("OK Zip teste.zip opened...\n"); int err = unzGoToFirstFile(zfile);/*go to first file in zip*/ if (err != UNZ_OK) { printf("error %d with zipfile in unzGoToFirstFile\n", err); unzClose(zfile);/*close zip*/ } /*At this point zfile points to the first file contained in the zip*/ char filename_inzip[256] = {0};/* The file name will be returned here */ unz_file_info file_info = {0};/*strcuture with info of the first file*/ err = unzGetCurrentFileInfo(zfile, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0); if (err != UNZ_OK) { printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); } else { int len = 8192;/*size of chunk*/ char buffer[8192]={0};/*buffer used to save uncompressed data*/ printf("name of first file is :%s\n",filename_inzip); printf("uncompressed_size = %d\n",file_info.uncompressed_size); /*Use your password here, the same one used to create your zip */ err = unzOpenCurrentFilePassword(zfile, "yourpassword"); if (err != UNZ_OK) printf("error %d with zipfile in unzOpenCurrentFilePassword\n", err); else printf("password ok\n"); FILE *fp = fopen(filename_inzip, "wb");/*file for data binary type*/ if (fp != NULL) { do {/*read the current file returned by unzGoToFirstFile to buffer in chunks of the 8192*/ err = unzReadCurrentFile(zfile, &buffer, len ); if (err < 0) { printf("error %d with zipfile in unzReadCurrentFile\n", err); break; } if (err == 0) break; /*Save the chunk read to the file*/ if (fwrite(&buffer, err, 1, fp) != 1)/*if error break*/ { printf("error %d in writing extracted file\n", errno); err = UNZ_ERRNO; break; }/*else continue*/ } while (err > 0); /*close file*/ fclose(fp); } } unzClose(zfile); 
0
source share

Source: https://habr.com/ru/post/651362/


All Articles