2011-01-22 19 views
8

Windowsでパスワードで保護されたzipファイルを作成できるCライブラリを知っている人はいますか?組み込みのzipユーティリティを使用してzipファイルをパスワードで保護するオプションがWindows 7から削除されたようですが、これは問題ではないと思われます。Windowsでパスワードで保護されたzipファイルを作成できるC zipライブラリですか?

zziplibまたは7-Zip SDKでこれを行うことはできますか?

答えて

2

7 - ジップSDK(LZMA SDK)をパスワード保護されたアーカイブをサポートしています。 SOポスト関連


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

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

+0

LZMA SDKは動作するように見えますが、バイナリディストリビューションはありません。 – freedrull

+0

LZMA SDKは使用するのに苦労してしまいました。アーカイブをパスワードで保護する機能を見つけることができませんでした。しかし、この小さなlibは、使用するケーキの一片でした! http://www.codeproject.com/KB/files/zip_utils.aspx – freedrull

+0

しかし、作成したパスワードで保護されたzipファイルは、Windows 7で動作しません... Windows 7は、それらを開くときに無効であると主張します。 – freedrull

0

MINIZIP +のzlibのは、AES 256暗号化をサポートしており、非常に使いやすいです!

minizip unzip.cに基づくコード。 stdio.h zip.h unzip.hをインクルードする

まず、ファイル内にパスワード付きのzipファイルを作成します。 zipファイルは、実行可能ファイルと同じディレクトリになければなりません。 生成されたプログラムのディレクトリにあるプロンプトからプログラムを実行します。この例では、最初のファイルのみが抽出されます。

/*-----------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); 
関連する問題