Skip to content

Commit 18b6e47

Browse files
FastJack2FastJack2
authored andcommitted
Merge PR #260, Fix AES256 encryption
Fixes #181 by using an empty IV for AES encryption instead of the second derived key Co-authored-by: FastJack2 <FastJack2@users.noreply.github.com>
1 parent 88302c5 commit 18b6e47

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,17 @@ public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMo
7878

7979
// Performs the equivalent of derive_key in Dr Brian Gladman's pwd2key.c
8080
var pdb = new Rfc2898DeriveBytes(key, saltBytes, KEY_ROUNDS);
81-
var rm = Aes.Create();
81+
var rm = Aes.Create();
8282
rm.Mode = CipherMode.ECB; // No feedback from cipher for CTR mode
8383
_counterNonce = new byte[_blockSize];
84-
byte[] byteKey1 = pdb.GetBytes(_blockSize);
85-
byte[] byteKey2 = pdb.GetBytes(_blockSize);
86-
_encryptor = rm.CreateEncryptor(byteKey1, byteKey2);
84+
byte[] key1bytes = pdb.GetBytes(_blockSize);
85+
byte[] key2bytes = pdb.GetBytes(_blockSize);
86+
87+
// Use empty IV for AES
88+
_encryptor = rm.CreateEncryptor(key1bytes, new byte[16]);
8789
_pwdVerifier = pdb.GetBytes(PWD_VER_LENGTH);
8890
//
89-
_hmacsha1 = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA1, byteKey2);
91+
_hmacsha1 = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA1, key2bytes);
9092
_writeMode = writeMode;
9193
}
9294

0 commit comments

Comments
 (0)