Skip to content

Commit 5cca93d

Browse files
Numpsypiksel
authored andcommitted
Merge PR #329: Do not set the StrongEncryption flag for WinZipAes encrypted entries
Change ZipEntry.ProcessAESExtraData to not set the StrongEncryption flag for WinZipAes encrypted entries.
1 parent 5d02051 commit 5cca93d

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,10 +1131,9 @@ private void ProcessAESExtraData(ZipExtraData extraData)
11311131
{
11321132
if (extraData.Find(0x9901))
11331133
{
1134-
// Set version and flag for Zipfile.CreateAndInitDecryptionStream
1134+
// Set version for Zipfile.CreateAndInitDecryptionStream
11351135
versionToExtract = ZipConstants.VERSION_AES; // Ver 5.1 = AES see "Version" getter
1136-
// Set StrongEncryption flag for ZipFile.CreateAndInitDecryptionStream
1137-
Flags = Flags | (int)GeneralBitFlags.StrongEncryption;
1136+
11381137
//
11391138
// Unpack AES extra data field see http://www.winzip.com/aes_info.htm
11401139
int length = extraData.ValueLength; // Data size currently 7

src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,23 +3565,9 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
35653565
{
35663566
CryptoStream result = null;
35673567

3568-
if ((entry.Version < ZipConstants.VersionStrongEncryption)
3569-
|| (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0)
3570-
{
3571-
var classicManaged = new PkzipClassicManaged();
3572-
3573-
OnKeysRequired(entry.Name);
3574-
if (HaveKeys == false)
3575-
{
3576-
throw new ZipException("No password available for encrypted stream");
3577-
}
3578-
3579-
result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
3580-
CheckClassicPassword(result, entry);
3581-
}
3582-
else
3568+
if (entry.CompressionMethodForHeader == CompressionMethod.WinZipAES)
35833569
{
3584-
if (entry.Version == ZipConstants.VERSION_AES)
3570+
if (entry.Version >= ZipConstants.VERSION_AES)
35853571
{
35863572
//
35873573
OnKeysRequired(entry.Name);
@@ -3610,6 +3596,28 @@ private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
36103596
throw new ZipException("Decryption method not supported");
36113597
}
36123598
}
3599+
else
3600+
{
3601+
if ((entry.Version < ZipConstants.VersionStrongEncryption)
3602+
|| (entry.Flags & (int)GeneralBitFlags.StrongEncryption) == 0)
3603+
{
3604+
var classicManaged = new PkzipClassicManaged();
3605+
3606+
OnKeysRequired(entry.Name);
3607+
if (HaveKeys == false)
3608+
{
3609+
throw new ZipException("No password available for encrypted stream");
3610+
}
3611+
3612+
result = new CryptoStream(baseStream, classicManaged.CreateDecryptor(key, null), CryptoStreamMode.Read);
3613+
CheckClassicPassword(result, entry);
3614+
}
3615+
else
3616+
{
3617+
// We don't support PKWare strong encryption
3618+
throw new ZipException("Decryption method not supported");
3619+
}
3620+
}
36133621

36143622
return result;
36153623
}

0 commit comments

Comments
 (0)