SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Extracting password protected file

Last post 09-17-2007 10:12 PM by JohnReilly. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 09-05-2007 2:06 PM

    • lewin
    • Not Ranked
    • Joined on 09-05-2007
    • Posts 3

    Extracting password protected file

    Hi

     I'm new to SharpZipLib so pleased excuse any crazy errors!

     I have to write a function to zip and password protect a single file. The following code works correctly - when run directly from a vb.net (2005) form. I can extract the zipped file from just windows compress folders, or 7-Zip file manger, or WinZip - so no problem there. ( I've also used the ZipOutputStream - with no problems.)

    --------------

    Dim oZip As New ICSharpCode.SharpZipLib.Zip.FastZip '(_ZipEvents)

    Dim spwd As String = "password"

    Dim sfolder As String = "c:\temp\macs\singlefile"

    Dim sDestfile As String = "c:\temp\createziptest6.zip"

    oZip.CreateEmptyDirectories = False

    oZip.Password = spwd '"password"

    oZip.CreateZip(sDestfile, sfolder, False, "", "")

    oZip = Nothing

    -------

     However - if i wrap the code in a class - I cannot extract any files correctly. All give me the "incorrect password" error. This is wrong - since the password is correct!

    The function below is used in my wrapper class - and to all intense and purposes its the same!  Please can anyone shed any light on this for me?

    I'm using build 0.85.3.365 of the library, running with VS2005.net professional, windows XP profession - (with windows update switched on)

    thanks in advance!

    Lewin 

     

    Friend Function FastZip(ByVal sSourceFileName As String, Optional ByVal sPassword As String = "") As ReturnValuesEnum

    Dim sDest As String = System.IO.Path.ChangeExtension(sSourceFileName, ".zip")

    Dim eRet As ReturnValuesEnum = ReturnValuesEnum.rvFalse

    Dim oZip As New ICSharpCode.SharpZipLib.Zip.FastZip

    Dim strSourceFolder As String = My.Computer.FileSystem.GetParentPath(sSourceFileName)

    Dim strNameOnly As String = My.Computer.FileSystem.GetName(sSourceFileName)

    Dim strlocalPW As String = sPassword

    Try

    If My.Computer.FileSystem.FileExists(sDest) Then

    My.Computer.FileSystem.DeleteFile(sDest)

    End If

    oZip.CreateEmptyDirectories = False

    oZip.Password = strlocalPW '"password" 'sPassword

    oZip.CreateZip(sDest, strSourceFolder, False, strNameOnly, "")

    eRet = ReturnValuesEnum.rvTrue

    Catch ex As Exception

    _ZipException = ex

    eRet = ReturnValuesEnum.rvError

    Finally

    oZip = Nothing

    End Try

    Return eRet

    End Function

     

     

  • 09-06-2007 3:57 AM In reply to

    Re: Extracting password protected file

    Hi,

    I have if you use hard coded values rather than parameters do it work?  Or have you debugged to see that all parameters are as expected?

     

    Cheers,

    -jr-

     

  • 09-06-2007 9:18 AM In reply to

    • knave
    • Not Ranked
    • Joined on 09-06-2007
    • Posts 1

    Re: Extracting password protected file

    Hi there, I've tested and proven that on the current release v0.85.3, the password encryption is broken.

    Base on similar codes when I reverted to v0.85.0, it worked perfectly.

    By setting a password value to the ZipOutputStream instance as well as the ZipEntry (IsCrypted=true property), the contents in the  generated zip file cannot be extracted. I've tested with 7z, WinRar and Vista's Compressed Folders to try to extract the files, but it throws a file is broken error.

    Knave 

     

     

     

  • 09-06-2007 10:32 AM In reply to

    • lewin
    • Not Ranked
    • Joined on 09-05-2007
    • Posts 3

    Re: Extracting password protected file

    Hi

     Yes - I tried a variety of combinations  ( hard coding etc) in case there was something crazy going on and I was missing something! After more testing, it seems that the code does work from anywhere - but only on small (2K approx) files; I only zipping CSV files which will normally be a few hundred K - 1.5 Mb max.

    Interestingly, reading another post on the forum, I "discovered" the zipfile class. I change the code to use that - and it now works! However, I'd be interested to know why on earth my first code fails. Could it be something to do with the compression you are using? I did play about with the compression settings, but with no joy.

    I did try and post my class here - but it appears my sys admins blocked it. I'l be working from home tomorrow - so I'll try again then :-)

    Thanks for your reply - much appreciated!

    lewin

  • 09-07-2007 1:47 PM In reply to

    Re: Extracting password protected file

    Hi,

    Its uncovered a bug that has been lurking for a while!  Occasionally encryption would lose the plot slightly and corrupt data due to an overrun which wasnt encountered a fair portion of the time (including unit tests).  I think that ZipFile will be in the same boat but characteristics like buffer sizes etc can differ so it may appear to work.

    I have fixed this and will do a release a soon as I can get it onto the site as I see this a somewhat nasty.

    Cheers, 

    -jr-.

     

  • 09-10-2007 11:53 AM In reply to

    Re: Extracting password protected file

    There is now a release available 0.085.4 which fixes this problem.

    hth, -jr-

     

  • 09-17-2007 5:18 PM In reply to

    • lewin
    • Not Ranked
    • Joined on 09-05-2007
    • Posts 3

    Re: Extracting password protected file

    Thanks John - much appreciated!

    I'll download  and test the new build asap. My apologies for not replying sooner - i was on hols last week wondering around the Welsh mountains, eating Ice cream and generally being soaked by my 4 year old!

    lewin

  • 09-17-2007 10:12 PM In reply to

    Re: Extracting password protected file

    Ah,

     The joys of parenthood are many and wonderous :-)
     

Page 1 of 1 (8 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.