mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Compare commits
1 Commits
copilot/su
...
Issue-197
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af2408de74 |
@@ -9,10 +9,11 @@ namespace SharpCompress.Common.Zip
|
||||
{
|
||||
private static readonly CRC32 crc32 = new CRC32();
|
||||
private readonly UInt32[] _Keys = {0x12345678, 0x23456789, 0x34567890};
|
||||
private readonly string password;
|
||||
|
||||
private PkwareTraditionalEncryptionData(string password)
|
||||
{
|
||||
Initialize(password);
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
private byte MagicByte
|
||||
@@ -28,6 +29,7 @@ namespace SharpCompress.Common.Zip
|
||||
byte[] encryptionHeader)
|
||||
{
|
||||
var encryptor = new PkwareTraditionalEncryptionData(password);
|
||||
encryptor.InitializeKeys();
|
||||
byte[] plainTextHeader = encryptor.Decrypt(encryptionHeader, encryptionHeader.Length);
|
||||
if (plainTextHeader[11] != (byte)((header.Crc >> 24) & 0xff))
|
||||
{
|
||||
@@ -84,7 +86,7 @@ namespace SharpCompress.Common.Zip
|
||||
return cipherText;
|
||||
}
|
||||
|
||||
private void Initialize(string password)
|
||||
internal void InitializeKeys()
|
||||
{
|
||||
byte[] p = StringToByteArray(password);
|
||||
for (int i = 0; i < password.Length; i++)
|
||||
|
||||
@@ -147,6 +147,7 @@ namespace SharpCompress.Common.Zip
|
||||
}
|
||||
if (Header.PkwareTraditionalEncryptionData != null)
|
||||
{
|
||||
Header.PkwareTraditionalEncryptionData.InitializeKeys();
|
||||
return new PkwareTraditionalCryptoStream(plainStream, Header.PkwareTraditionalEncryptionData,
|
||||
CryptoMode.Decrypt);
|
||||
}
|
||||
|
||||
@@ -183,6 +183,32 @@ namespace SharpCompress.Test
|
||||
Assert.Equal(new FileInfo(scratchPath1).Length, new FileInfo(scratchPath2).Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_Read_Entry_Twice()
|
||||
{
|
||||
string scratchPath = "C:\\Users\\adam\\Downloads\\Archive1.zip";
|
||||
|
||||
using (var archive = ArchiveFactory.Open(scratchPath, new ReaderOptions()
|
||||
{
|
||||
Password = "12345678"
|
||||
}))
|
||||
{
|
||||
var entries = archive.Entries.Where(entry => !entry.IsDirectory);
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
entryStream.CopyTo(memoryStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_Removal_Poly()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user