2014-03-02 79 views
0

我使用7zipsharp庫創建的程序中有sfx文件。仍然當我直接執行雙擊文件sfx如果使用錯誤的密碼,但仍然提取其中的文件大小爲0字節,如果任何人應該添加另一種模式功能'壓縮',以便當我執行文件sfx錯誤的密碼文件根本沒有被提取。雖然輸入了錯誤的密碼,sfx文件會解壓縮

error if wrong password

extracted files

壓縮代碼:

public void Compress() 
{ 
    SevenZipCompressor.SetLibraryPath("7z.dll"); 
    SevenZipCompressor cmp = new SevenZipCompressor(); 
    cmp.Compressing += new EventHandler<ProgressEventArgs>(cmp_Compressing); 
    cmp.FileCompressionStarted += new EventHandler<FileNameEventArgs>(cmp_StartCompress); 
    cmp.CompressionFinished += new EventHandler<EventArgs>(cmp_CompleteCompressed); 
    cmp.ArchiveFormat = OutArchiveFormat.SevenZip; 
    cmp.CompressionLevel = CompressionLevel.Normal; 
    cmp.CompressionMethod = CompressionMethod.Lzma; 
    cmp.CompressionMode = CompressionMode.Create; 
    string password = txtPasswordEn.Text; 
    string DirFile = tempFolder; 
    string NameFileCompress = Path.Combine(txtOutputFileEn.Text, txtNameFile.Text) + (".zip"); 
    cmp.BeginCompressDirectory(DirFile, NameFileCompress, password, ".",true); 
} 

創建SFX代碼:

public void CreateSfx() 
{ 
    string location = Path.Combine(txtOutputFileEn.Text, txtNameFile.Text); 
    string nameZip = location + (".zip"); 
    string nameExe = location + (".exe"); 
    SfxModule mdl = SfxModule.Extended; 
    SevenZipSfx sfx = new SevenZipSfx(mdl); 
    sfx.ModuleFileName = @"7z.sfx"; 
    sfx.MakeSfx(nameZip, nameExe); 
} 
+0

在它的基礎版本,加密僅適用於文件內容,而不是元數據(包括:

對於文件格式,你可以使用EncryptHeaders屬性實現文件名加密文件名)。 ZIP文件格式規範版本6.2描述瞭如何額外加密中央目錄。此外,還需要禁止或混淆本地文件頭信息。看來SevenZip還不支持這一點。 – Codo

+0

如果是這樣,我嘗試另一個庫。因爲它不支持七zipsharp – sloqye

回答

1

我剛看到你沒有創建一個.zip文件但.7z文件(然後將其轉換爲自解壓檔案E)。

cmp.EncryptHeaders = true; 
+0

你是對的。我加了它,它工作。謝謝 – sloqye