簡體   English   中英

SevenZipSharp庫:無法加密標頭

[英]SevenZipSharp library: Cannot encrypt headers

我的任務是使用SevenZipSharp庫創建受密碼保護的ZIP。

我設法用密碼鎖定了文件內容,但是可以在任何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");
    }

查看源代碼,似乎該標志生效的唯一方法是對SevenZip使用OutArchiveFormat

從源代碼:

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM