Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,10 +1131,9 @@ private void ProcessAESExtraData(ZipExtraData extraData)
{
if (extraData.Find(0x9901))
{
// Set version and flag for Zipfile.CreateAndInitDecryptionStream
// Set version for Zipfile.CreateAndInitDecryptionStream
versionToExtract = ZipConstants.VERSION_AES; // Ver 5.1 = AES see "Version" getter
// Set StrongEncryption flag for ZipFile.CreateAndInitDecryptionStream
Flags = Flags | (int)GeneralBitFlags.StrongEncryption;

//
// Unpack AES extra data field see http://www.winzip.com/aes_info.htm
int length = extraData.ValueLength; // Data size currently 7
Expand Down
40 changes: 24 additions & 16 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3542,23 +3542,9 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
{
CryptoStream result = null;

if ((entry.Version < ZipConstants.VersionStrongEncryption)
|| (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0)
{
var classicManaged = new PkzipClassicManaged();

OnKeysRequired(entry.Name);
if (HaveKeys == false)
{
throw new ZipException("No password available for encrypted stream");
}

result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
CheckClassicPassword(result, entry);
}
else
if (entry.CompressionMethodForHeader == CompressionMethod.WinZipAES)
{
if (entry.Version == ZipConstants.VERSION_AES)
if (entry.Version >= ZipConstants.VERSION_AES)
{
//
OnKeysRequired(entry.Name);
Expand Down Expand Up @@ -3587,6 +3573,28 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
throw new ZipException("Decryption method not supported");
}
}
else
{
if ((entry.Version < ZipConstants.VersionStrongEncryption)
|| (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0)
{
var classicManaged = new PkzipClassicManaged();

OnKeysRequired(entry.Name);
if (HaveKeys == false)
{
throw new ZipException("No password available for encrypted stream");
}

result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
CheckClassicPassword(result, entry);
}
else
{
// We don't support PKWare strong encryption
throw new ZipException("Decryption method not supported");
}
}

return result;
}
Expand Down