The following code seems to mostly work fine. But as soon as I apply an encryption value (commented out code) to the ZipEntry, everything seems to fall apart. I get the following exception: ICSharpCode.SharpZipLib.Zip.ZipException: 'The compression method for this entry is not supported'. I'm currently at a loss trying to figure out what is wrong with the "compression method". I've tried all of them, and setting the compression level to 0. Nothing seems to work. Can someone help me?
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.IO;
public byte[] ZipPayload(byte[] data)
{
using (var outputStream = new MemoryStream())
using (var zipStream = new ZipOutputStream(outputStream))
{
zipStream.Password = "abc";
zipStream.SetLevel(0);
var zipEntry = new ZipEntry("ZipEntry")
{
//AESKeySize = 128,
//CompressionMethod = CompressionMethod.Stored
//CompressionMethod = CompressionMethod.Deflated
//CompressionMethod = CompressionMethod.Deflate64
//CompressionMethod = CompressionMethod.BZip2
//CompressionMethod = CompressionMethod.LZMA
//CompressionMethod = CompressionMethod.PPMd
//CompressionMethod = CompressionMethod.WinZipAES
//CompressionMethod = CompressionMethod.WinZipAES
};
zipStream.PutNextEntry(zipEntry);
var inputMemoryStream = new MemoryStream(data);
StreamUtils.Copy(inputMemoryStream, zipStream, new byte[4096]);
zipStream.CloseEntry();
zipStream.IsStreamOwner = false;
return outputStream.ToArray();
}
}
public byte[] UnzipPayload(byte[] data)
{
using (var outputStream = new MemoryStream())
using (var inputStream = new MemoryStream(data))
{
using (var zipStream = new ZipInputStream(inputStream))
{
zipStream.Password = "abc";
zipStream.GetNextEntry();
zipStream.CopyTo(outputStream);
}
return outputStream.ToArray();
}
}