[英]C zip library that can create password protected zip files on windows?
Anyone know of a C library that can create password protected zip files on windows? 有人知道可以在Windows上创建受密码保护的zip文件的C库吗? It appears that the option to password protect zip files with the built-in zip utility has been removed from windows 7, but I don't think this is an issue.
似乎已经从Windows 7中删除了使用内置zip工具密码保护zip文件的选项,但我不认为这是一个问题。
Can either zziplib or the 7-Zip SDK do this? zziplib或7-Zip SDK可以这样做吗?
7-Zip SDK (LZMA SDK) supports password protected archive. 7-Zip SDK(LZMA SDK)支持受密码保护的存档。
Related SO post: 相关SO帖子:
https://stackoverflow.com/questions/221049/how-secure-is-7-zip https://stackoverflow.com/questions/221049/how-secure-is-7-zip
LZMA SDK: LZMA SDK:
http://www.7-zip.org/sdk.html http://www.7-zip.org/sdk.html
If you can use .NET, check out DotNetZip: http://dotnetzip.codeplex.com/ 如果您可以使用.NET,请查看DotNetZip: http ://dotnetzip.codeplex.com/
C++ .NET example to create password-protected ZIP: http://cheeso.members.winisp.net/DotNetZipHelp/Code%20Examples/Cpp.htm 用于创建受密码保护的ZIP的C ++ .NET示例: http : //cheeso.members.winisp.net/DotNetZipHelp/Code%20Examples/Cpp.htm
MINIZIP + zlib supports AES 256 encryption, and is very easy to use! MINIZIP + zlib支持AES 256加密,非常易于使用!
Code based on minizip unzip.c. 代码基于minizip unzip.c。 include stdio.h zip.h unzip.h
包括stdio.h zip.h unzip.h
First, create a zip with a file inside with a password. 首先,使用密码创建一个带有文件的zip。 The zip file must be in the same directory as the executable.
zip文件必须与可执行文件位于同一目录中。 Run the program from a prompt in the directory of the generated program.
从生成的程序的目录中的提示符运行该程序。 This example only extracts the first file!
此示例仅提取第一个文件!
/*-----------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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.