SharpDevelop Community

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

Archive corrupted when using encryption

Last post 12-04-2006 3:12 PM by Daniel F. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 11-24-2006 7:03 PM

    • DSI
    • Not Ranked
    • Joined on 11-24-2006
    • Posts 2

    Archive corrupted when using encryption

    I get following error message when I try to extract the encrypted archive:

    when used winRAR:

    WinRAR: Diagnostic messages
    The archive is corrupt

    when used winZip:

    Extracting to "C:\projects\USC\Harmony\Source\HarmonyZip\TestZip\bin\Debug\testzip\"

    Use Path: yes Overlay Files: no

    warning [file name with full path]: extra 4 bytes at beginning or within Zip file (attempting to process anyway)

    skipping: test.pdf: this file is not in the standard Zip 2.0 format

    Please see www.winzip.com/zip20.htm for more information

    error: no files were found - nothing to do

     

    Below is the test function that I am using:

    if (FileNameCollection.Count == 0)

    {

    return false;

    }

    try

    {

     

    // 'using' statements gaurantee the stream is closed properly which is a big source

    // of problems otherwise. Its exception safe as well which is great.

    using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFileName)) )

    {

    s.Password = "good";

    s.SetLevel(6); // 0 - store only to 9 - means best compression

     

    byte[] buffer = new byte[4096];

     

    foreach (string fileName in FileNameCollection)

    {

     

    // Using GetFileName makes the result compatible with XP

    // as the resulting path is not absolute.

    if (File.Exists(fileName))

    {

    ZipEntry entry = new ZipEntry(Path.GetFileName(fileName));

     

    // Setup the entry data as required.

     

    // Crc and size are handled by the library for seakable streams

    // so no need to do them here.

    // Could also use the last write time or similar for the file.

    entry.DateTime = DateTime.Now;

    s.PutNextEntry(entry);

     

    using ( FileStream fs = File.OpenRead(fileName))

    {

     

    // Using a fixed size buffer here makes no noticeable difference for output

    // but keeps a lid on memory usage.

    int sourceBytes;

    do

    {

    sourceBytes = fs.Read(buffer, 0, buffer.Length);

    s.Write(buffer, 0, sourceBytes);

    } while ( sourceBytes > 0 );

    }

    }

    }

     

     

    // Finish is important to ensure trailing information for a Zip file is appended. Without this

    // the created file would be invalid.

    s.Finish();

     

    // Close is important to wrap things up and unlock the file.

    s.Close();

    }

    }

    catch (Exception ex)

    {

    //Console.WriteLine("Exception during processing {0}", ex);

     

    // No need to rethrow the exception as for our purposes its handled.

    }

    return true;

    Any help will be appreciated.

     

    Filed under:
  • 11-27-2006 12:54 AM In reply to

    Re: Archive corrupted when using encryption

    It might be due to a descriptor being appended to the archive data but thats only a guess.

    If you run AEX (http://www.geocities.com/licamft) on the archive what does it say I am wondering....

    Cheers, -jr-

  • 11-27-2006 4:50 PM In reply to

    • DSI
    • Not Ranked
    • Joined on 11-24-2006
    • Posts 2

    Re: Archive corrupted when using encryption

    Thank you for responding to my query.

    When I run AEX I get following message:

    myzip.zip is 59077 bytes long

    Exception Wrong Central Directory signature

    Done

    Also, wanted to mention that "Archive is corrupt" is warning message, and I can still unzip the PDF file that I archived, and it does not look corrupted, it could be opened without any issues. 

     

     

  • 11-28-2006 9:46 PM In reply to

    Re: Archive corrupted when using encryption

    Can you send me the file?
  • 12-04-2006 3:12 PM In reply to

    Re: Archive corrupted when using encryption

    Hallo,

    i did have the same problem while using encryption. After reading another thread on problems with set size i set the size on the entry before putting it to the zipoutputstream like this:

        ZipOutputStream z =  new ZipOutPutStream(System.IO.File.Open(@"C:\Test.zip", FileMode.Create));

        _ZipOut.Password = "Hi";

        ZipEntry Entry = new ZipEntry();

        byte[] data = System.Text.Encoding.ASCII.GetBytes("Hallo"); 

        Entry.Size = data.length;

       z.PutNextEntry();

       z.Write(data, 0, data.Length);

       z.Close();

    this works for me in case of encryption. 

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