diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
index 4afc1bf75..c28b603e3 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
@@ -1850,6 +1850,9 @@ public void Add(ZipEntry entry)
/// The source of the data for this entry.
/// The entry to add.
/// This can be used to add file entries with a custom data source.
+ ///
+ /// The encryption method specified in is unsupported.
+ ///
public void Add(IStaticDataSource dataSource, ZipEntry entry)
{
if (entry == null)
@@ -1862,6 +1865,13 @@ public void Add(IStaticDataSource dataSource, ZipEntry entry)
throw new ArgumentNullException(nameof(dataSource));
}
+ // We don't currently support adding entries with AES encryption, so throw
+ // up front instead of failing or falling back to ZipCrypto later on
+ if (entry.AESKeySize > 0)
+ {
+ throw new NotSupportedException("Creation of AES encrypted entries is not supported");
+ }
+
CheckUpdating();
AddUpdate(new ZipUpdate(dataSource, entry));
diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
index 50adeffac..c79137130 100644
--- a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
+++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
@@ -1547,5 +1547,27 @@ public void HostSystemPersistedFromZipFile()
}
}
}
+
+ ///
+ /// Refs https://github.com/icsharpcode/SharpZipLib/issues/385
+ /// Trying to add an AES Encrypted entry to ZipFile should throw as it isn't supported
+ ///
+ [Test]
+ [Category("Zip")]
+ public void AddingAnAESEncryptedEntryShouldThrow()
+ {
+ var memStream = new MemoryStream();
+ using (ZipFile zof = new ZipFile(memStream))
+ {
+ var entry = new ZipEntry("test")
+ {
+ AESKeySize = 256
+ };
+
+ zof.BeginUpdate();
+ var exception = Assert.Throws(() => zof.Add(new StringMemoryDataSource("foo"), entry));
+ Assert.That(exception.Message, Is.EqualTo("Creation of AES encrypted entries is not supported"));
+ }
+ }
}
}