private static void AddExtraDataAES(ZipEntry entry, ZipExtraData extraData) { extraData.StartNewEntry(); extraData.AddLeShort(2); extraData.AddLeShort(17729); extraData.AddData(entry.AESEncryptionStrength); extraData.AddLeShort((int)entry.CompressionMethod); extraData.AddNewEntry(39169); }
private static void AddExtraDataAES(ZipEntry entry, ZipExtraData extraData) { extraData.StartNewEntry(); extraData.AddLeShort(2); extraData.AddLeShort(0x4541); extraData.AddData(entry.AESEncryptionStrength); extraData.AddLeShort((int) entry.CompressionMethod); extraData.AddNewEntry(0x9901); }
private static void AddExtraDataAES(ZipEntryM entry, ZipExtraData extraData) { // Vendor Version: AE-1 IS 1. AE-2 is 2. With AE-2 no CRC is required and 0 is stored. const int VENDOR_VERSION = 2; // Vendor ID is the two ASCII characters "AE". const int VENDOR_ID = 0x4541; //not 6965; extraData.StartNewEntry(); // Pack AES extra data field see http://www.winzip.com/aes_info.htm //extraData.AddLeShort(7); // Data size (currently 7) extraData.AddLeShort(VENDOR_VERSION); // 2 = AE-2 extraData.AddLeShort(VENDOR_ID); // "AE" extraData.AddData(entry.AESEncryptionStrength); // 1 = 128, 2 = 192, 3 = 256 extraData.AddLeShort((int)entry.CompressionMethod); // The actual compression method used to compress the file extraData.AddNewEntry(0x9901); }
private static void AddExtraDataAES(ZipEntry entry, ZipExtraData extraData) { // Vendor Version: AE-1 IS 1. AE-2 is 2. With AE-2 no CRC is required and 0 is stored. const int VENDOR_VERSION = 2; // Vendor ID is the two ASCII characters "AE". const int VENDOR_ID = 0x4541; //not 6965; extraData.StartNewEntry(); // Pack AES extra data field see http://www.winzip.com/aes_info.htm //extraData.AddLeShort(7); // Data size (currently 7) extraData.AddLeShort(VENDOR_VERSION); // 2 = AE-2 extraData.AddLeShort(VENDOR_ID); // "AE" extraData.AddData(entry.AESEncryptionStrength); // 1 = 128, 2 = 192, 3 = 256 extraData.AddLeShort((int) entry.CompressionMethod); // The actual compression method used to compress the file extraData.AddNewEntry(0x9901); }
public void PasswordCheckingWithDateInExtraData() { MemoryStream ms = new MemoryStream(); DateTime checkTime = new DateTime(2010, 10, 16, 0, 3, 28); using (ZipOutputStream zos = new ZipOutputStream(ms)) { zos.IsStreamOwner = false; zos.Password = "******"; ZipEntry ze = new ZipEntry("uno"); ze.DateTime = new DateTime(1998, 6, 5, 4, 3, 2); ZipExtraData zed = new ZipExtraData(); zed.StartNewEntry(); zed.AddData(1); TimeSpan delta = checkTime.ToUniversalTime() - new System.DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime(); int seconds = (int)delta.TotalSeconds; zed.AddLeInt(seconds); zed.AddNewEntry(0x5455); ze.ExtraData = zed.GetEntryData(); zos.PutNextEntry(ze); zos.WriteByte(54); } ms.Position = 0; using (ZipInputStream zis = new ZipInputStream(ms)) { zis.Password = "******"; ZipEntry uno = zis.GetNextEntry(); byte theByte = (byte)zis.ReadByte(); Assert.AreEqual(54, theByte); Assert.AreEqual(-1, zis.ReadByte()); Assert.AreEqual(checkTime, uno.DateTime); } }
public void BasicOperations() { ZipExtraData zed = new ZipExtraData(null); Assert.AreEqual(0, zed.Length); zed = new ZipExtraData(new byte[] { 1, 0, 0, 0 }); Assert.AreEqual(4, zed.Length, "A length should be 4"); ZipExtraData zed2 = new ZipExtraData(); Assert.AreEqual(0, zed2.Length); zed2.AddEntry(1, new byte[] { }); byte[] data = zed.GetEntryData(); for (int i = 0; i < data.Length; ++i) { Assert.AreEqual(zed2.GetEntryData()[i], data[i]); } Assert.AreEqual(4, zed2.Length, "A1 length should be 4"); bool findResult = zed.Find(2); Assert.IsFalse(findResult, "A - Shouldnt find tag 2"); findResult = zed.Find(1); Assert.IsTrue(findResult, "A - Should find tag 1"); Assert.AreEqual(0, zed.ValueLength, "A- Length of entry should be 0"); Assert.AreEqual(-1, zed.ReadByte()); Assert.AreEqual(0, zed.GetStreamForTag(1).Length, "A - Length of stream should be 0"); zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3 }); Assert.AreEqual(7, zed.Length, "Expected a length of 7"); findResult = zed.Find(1); Assert.IsTrue(findResult, "B - Should find tag 1"); Assert.AreEqual(3, zed.ValueLength, "B - Length of entry should be 3"); for (int i = 1; i <= 3; ++i) { Assert.AreEqual(i, zed.ReadByte()); } Assert.AreEqual(-1, zed.ReadByte()); Stream s = zed.GetStreamForTag(1); Assert.AreEqual(3, s.Length, "B.1 Stream length should be 3"); for (int i = 1; i <= 3; ++i) { Assert.AreEqual(i, s.ReadByte()); } Assert.AreEqual(-1, s.ReadByte()); zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3, 2, 0, 1, 0, 56 }); Assert.AreEqual(12, zed.Length, "Expected a length of 12"); findResult = zed.Find(1); Assert.IsTrue(findResult, "C.1 - Should find tag 1"); Assert.AreEqual(3, zed.ValueLength, "C.1 - Length of entry should be 3"); for (int i = 1; i <= 3; ++i) { Assert.AreEqual(i, zed.ReadByte()); } Assert.AreEqual(-1, zed.ReadByte()); findResult = zed.Find(2); Assert.IsTrue(findResult, "C.2 - Should find tag 2"); Assert.AreEqual(1, zed.ValueLength, "C.2 - Length of entry should be 1"); Assert.AreEqual(56, zed.ReadByte()); Assert.AreEqual(-1, zed.ReadByte()); s = zed.GetStreamForTag(2); Assert.AreEqual(1, s.Length); Assert.AreEqual(56, s.ReadByte()); Assert.AreEqual(-1, s.ReadByte()); zed = new ZipExtraData(); zed.AddEntry(7, new byte[] { 33, 44, 55 }); findResult = zed.Find(7); Assert.IsTrue(findResult, "Add.1 should find new tag"); Assert.AreEqual(3, zed.ValueLength, "Add.1 length should be 3"); Assert.AreEqual(33, zed.ReadByte()); Assert.AreEqual(44, zed.ReadByte()); Assert.AreEqual(55, zed.ReadByte()); Assert.AreEqual(-1, zed.ReadByte()); zed.AddEntry(7, null); findResult = zed.Find(7); Assert.IsTrue(findResult, "Add.2 should find new tag"); Assert.AreEqual(0, zed.ValueLength, "Add.2 length should be 0"); zed.StartNewEntry(); zed.AddData(0xae); zed.AddNewEntry(55); findResult = zed.Find(55); Assert.IsTrue(findResult, "Add.3 should find new tag"); Assert.AreEqual(1, zed.ValueLength, "Add.3 length should be 1"); Assert.AreEqual(0xae, zed.ReadByte()); Assert.AreEqual(-1, zed.ReadByte()); zed = new ZipExtraData(); zed.StartNewEntry(); zed.AddLeLong(0); zed.AddLeLong(-4); zed.AddLeLong(-1); zed.AddLeLong(long.MaxValue); zed.AddLeLong(long.MinValue); zed.AddLeLong(0x123456789ABCDEF0); zed.AddLeLong(unchecked((long)0xFEDCBA9876543210)); zed.AddNewEntry(567); s = zed.GetStreamForTag(567); long longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(0, longValue, "Expected long value of zero"); longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(-4, longValue, "Expected long value of -4"); longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(-1, longValue, "Expected long value of -1"); longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(long.MaxValue, longValue, "Expected long value of MaxValue"); longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(long.MinValue, longValue, "Expected long value of MinValue"); longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(0x123456789abcdef0, longValue, "Expected long value of MinValue"); longValue = ReadLong(s); Assert.AreEqual(longValue, zed.ReadLong(), "Read/stream mismatch"); Assert.AreEqual(unchecked((long)0xFEDCBA9876543210), longValue, "Expected long value of MinValue"); }