SevenZSharp Decode with password

6.3k views Asked by At

I work with SevenZSharp from here

for Decode file I use:

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

But I don't have information how to decode .7z file with password!? Please, help me. Thanks

2

There are 2 answers

12
Filip Ekberg On

By the look of the source code of SevenZSharp, it does not support password protected files.

Here's something else that might help you from codeplex. It seem to have an interface called ICryptoGetTextPassword that you might be able to use if the 7z is password protected.

Edit

With a bit further look at SevenZipSharp it seems that it should support password protected archives accroding to their project page ( http://sevenzipsharp.codeplex.com/ ):

  • Encryption and passwords are supported.

You need to download the latest code from Codeplex and build it yourself, in it you will have a class called SevenZipExtractor where you have the following constructor:

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

Note this is not the same as Seven7Sharp, this is SevenZipSharp, but it works with 7z.

0
user1432290 On

To use "SevenZipSharp" which DOES support passwords and a wide range of formats...

Import SevenZipSharp.dll into .Net project references...

Place "7zx64.dll" and "7z.dll" into the directory...

Then use this code to check the pass and extract if correct..

code

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