2013-01-14 25 views
0

我的任務是用SevenZipSharp庫創建密碼保護的ZIP。SevenZipSharp庫:無法加密標頭

我設法使用密碼鎖定文件內容,但可以在任何WinZip,7-Zip或Compressed文件夾中查看歸檔結構 - 文件名,目錄層次結構。

我用的是cmp.EncryptHeaders = true;但它似乎沒有任何效果...

如何我可以加密的文件和目錄的名字呢?謝謝。

static void Main(string[] args) 
    { 
     const string LibraryPath = @"C:\Program Files\7-Zip\7z.dll"; 
     SevenZipCompressor.SetLibraryPath(LibraryPath); 

     var cmp = new SevenZipCompressor(); 
     cmp.CompressionMethod = CompressionMethod.Default; 
     cmp.CompressionLevel = CompressionLevel.Fast; 
     cmp.ArchiveFormat = OutArchiveFormat.Zip; // compatible with WinZip and Compressed folder 
     cmp.ZipEncryptionMethod = ZipEncryptionMethod.ZipCrypto; // compatible with old WinZip 
     cmp.EncryptHeaders = true; 

     cmp.FileCompressionStarted += (sender, e) => 
     { 
      Console.WriteLine(((FileNameEventArgs)e).FileName); 
     }; 

     const string archive = @"C:\temp\12.3G.zip"; 
     File.Delete(archive); 
     cmp.CompressDirectory(@"C:\temp\Photos", archive, "password"); 
    } 

回答

2

查看源代碼,它出現該標誌生效的唯一方法是使用SevenZipOutArchiveFormat

從源代碼:

if (EncryptHeaders && _archiveFormat == OutArchiveFormat.SevenZip && !SwitchIsInCustomParameters("he")) 
{ 
    names.Add(Marshal.StringToBSTR("he")); 
    var tmp = new PropVariant {VarType = VarEnum.VT_BSTR, Value = Marshal.StringToBSTR("on")}; 
    values.Add(tmp); 
} 
+0

感謝。那麼沒有解決方案的標題? –

+1

這不是一個解決方案,因爲你想要你的格式爲Zip和EncryptHeaders只適用於SevenZip存檔。 –