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.