SevenZSharp用密码解码

时间:2011-11-08 07:43:42

标签: c# .net 7zip sevenzipsharp

我与here

的SevenZSharp合作

我使用的解码文件:

CompressionEngine.Current.Decoder.DecodeIntoDirectory(@"D:\target\host_update.7z", @"D:\target");

但是我没有关于如何用密码解码.7z文件的信息!?请帮我。感谢

2 个答案:

答案 0 :(得分:2)

使用支持密码和各种格式的“SevenZipSharp”......

将SevenZipSharp.dll导入.Net项目引用...

将“7zx64.dll”和“7z.dll”放入目录...

然后使用此代码检查传递并提取是否正确..

<强>码

Imports SevenZip
Public Class FrmMain
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Btn1.Click

    ''Call to set DLL depending on processor type''
    If Environment.Is64BitProcess Then
        SevenZip.SevenZipCompressor.SetLibraryPath("7zx64.dll")
    Else
        SevenZip.SevenZipCompressor.SetLibraryPath("7z.dll")
    End If

    ''Set Destination of extraction''
    Dim DestDir = Application.StartupPath

    Try
        ''Check file with password''
        Dim Ext As New SevenZipExtractor(Tb1.Text, Tb2.Text)

        If Ext.Check() Then
            ''Extract files to destination''
            Ext.BeginExtractArchive(DestDir)
        End If

    Catch ex As Exception
        MessageBox.Show(ex.ToString())
    End Try

End Sub
End Class

答案 1 :(得分:1)

看看SevenZSharp的源代码,它不支持受密码保护的文件。

Here's something else that might help you from codeplex。它似乎有一个名为ICryptoGetTextPassword的接口,如果7z受密码保护,您可以使用它。

修改

再看看SevenZipSharp,它似乎应该支持密码保护的档案,这些档案包含在他们的项目页面中http://sevenzipsharp.codeplex.com/):

  
      
  • 支持加密和密码。
  •   

您需要从Codeplex下载最新代码并自行构建,在其中您将拥有一个名为SevenZipExtractor的类,其中包含以下构造函数:

/// <summary>
/// Initializes a new instance of SevenZipExtractor class.
/// </summary>
/// <param name="archiveFullName">The archive full file name.</param>
/// <param name="password">Password for an encrypted archive.</param>
public SevenZipExtractor(string archiveFullName, string password)
    : base(password)
{
    Init(archiveFullName);
}

注意这与Seven7Sharp不同,这是SevenZipSharp,但它适用于7z