-
Steps to reproduceHi everyone, i've got this code public static void CreateZipPackage(string zipName, Dictionary<string, byte[]> files)
{
using(FileStream zip = File.Create(zipName))
{
using(ZipOutputStream zipStream = new ZipOutputStream(zip))
{
foreach (KeyValuePair<string, byte[]> kv in files)
{
// Compress the entry in the package
ZipEntry entry = new ZipEntry(kv.Key);
entry.AESKeySize = 256;
//Add an entry
zipStream.PutNextEntry(entry);
// Set the compression level 1~9
zipStream.SetLevel(5);
zipStream.Password = "PASSWORD";
//write
zipStream.Write(kv.Value, 0, kv.Value.Length);
}
}
}
} I noticed that i can view the content of the files in the ZIP even if it's password protected, so i've decided to add "entry.AESKeySize = 256;" to encrypt the files Expected behaviorI want to zip and encrypt multiple files in c# Actual behaviorError: Buffer cannot be null - parameter name: array Version of SharpZipLib1.2.0.246 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hm, you are setting the password after the entry has been added, that probably doesn't work. Try moving the // Set the compression level 1~9
zipStream.SetLevel(5);
zipStream.Password = "PASSWORD"; to before the Also, are you sure about that error message? It doesn't seem right. |
Beta Was this translation helpful? Give feedback.
-
I tried turning off the password in one of the zip output stream unit tests and got
Because Looks to be because some of the logic goes off entry.AESKeySize being set to a non-zero value (deciding whether to write the AES extra data etc), but them some of it goes off Entry.IsCrypted being true, which is only done automatically if a password has already been specified when the entry is added, so some of the other crypto bits get skipped. Gets itself in a bit of a mess basically. |
Beta Was this translation helpful? Give feedback.
-
Yeah, that's basically what I figured was going on. It should definitely throw there, the error messages of the type I think the original problem was caused by the same problem
|
Beta Was this translation helpful? Give feedback.
Hm, you are setting the password after the entry has been added, that probably doesn't work. Try moving the
to before the
foreach
loop.Also, are you sure about that error message? It doesn't seem right.
If you can give me the full exception I can look into what is going on...