Hi All!
Recently we decided to use AES encrypted zip files in our app and I have found a problem with this lib, it throws NotImplementedException when calling Dispose method on input stream for encrypted entry after reading is done.
Sample code to reproduce problem:
public void CloseStreamTest()
{
var _zipFile = new ZipFile(@"encrypted.zip") { Password = @"123456789" };
//File.txt is AES-256 encrypted file
var entryIdx = _zipFile.FindEntry(@"File.txt", true);
if (entryIdx >= 0)
{
var zipped = _zipFile.GetInputStream(entryIdx);
//We're able to get all data
ReadStream(original, zipped);
//Next statement throws NotImplementedException
zipped.Close();
}
}
I have created a patch for this. Changes include 2 files:
- Encryption\ZipAESTransform.cs
source lines 167-170
public byte[ TransformFinalBlock(byte[ inputBuffer, int inputOffset, int inputCount) {
throw new NotImplementedException("ZipAESTransform.TransformFinalBlock");
}
to (changed)
public byte[ TransformFinalBlock(byte[ inputBuffer, int inputOffset, int inputCount)
{
byte[ result;
if (!_finalised)
{
result = new byte[inputCount];
TransformBlock(inputBuffer, inputOffset, inputCount, result, 0);
}
else
{
result = new byte[0];
}
return result;
}
- Encryption\ZipAESStream.cs
source lines 132-166
_transform.TransformBlock(_slideBuffer,
_slideBufStartPos,
finalBlock,
outBuffer,
offset);
to (changed)
var fb = _transform.TransformFinalBlock(_slideBuffer,
_slideBufStartPos,
finalBlock);
Array.Copy(fb, 0, outBuffer, offset, fb.Length);
I will be glad to see this changes in SharpZipLib.
Best Regards