@@ -15,7 +15,7 @@ public interface ITaggedData
15
15
/// <summary>
16
16
/// Get the ID for this tagged data value.
17
17
/// </summary>
18
- short TagID { get ; }
18
+ ushort TagID { get ; }
19
19
20
20
/// <summary>
21
21
/// Set the contents of this instance from the data passed.
@@ -41,7 +41,7 @@ public class RawTaggedData : ITaggedData
41
41
/// Initialise a new instance.
42
42
/// </summary>
43
43
/// <param name="tag">The tag ID.</param>
44
- public RawTaggedData ( short tag )
44
+ public RawTaggedData ( ushort tag )
45
45
{
46
46
_tag = tag ;
47
47
}
@@ -51,7 +51,7 @@ public RawTaggedData(short tag)
51
51
/// <summary>
52
52
/// Get the ID for this tagged data value.
53
53
/// </summary>
54
- public short TagID
54
+ public ushort TagID
55
55
{
56
56
get { return _tag ; }
57
57
set { _tag = value ; }
@@ -100,7 +100,7 @@ public byte[] Data
100
100
/// <summary>
101
101
/// The tag ID for this instance.
102
102
/// </summary>
103
- private short _tag ;
103
+ private ushort _tag ;
104
104
105
105
private byte [ ] _data ;
106
106
@@ -139,7 +139,7 @@ public enum Flags : byte
139
139
/// <summary>
140
140
/// Get the ID
141
141
/// </summary>
142
- public short TagID
142
+ public ushort TagID
143
143
{
144
144
get { return 0x5455 ; }
145
145
}
@@ -328,7 +328,7 @@ public class NTTaggedData : ITaggedData
328
328
/// <summary>
329
329
/// Get the ID for this tagged data value.
330
330
/// </summary>
331
- public short TagID
331
+ public ushort TagID
332
332
{
333
333
get { return 10 ; }
334
334
}
@@ -475,6 +475,110 @@ public DateTime LastAccessTime
475
475
#endregion Instance Fields
476
476
}
477
477
478
+ /// <summary>
479
+ /// A TaggedData for handling WinzipAES extra data.
480
+ /// </summary>
481
+ /// <remarks>
482
+ /// See http://www.winzip.com/aes_info.htm for format documentation.
483
+ /// </remarks>
484
+ internal class WinZipAESTaggedData : ITaggedData
485
+ {
486
+ /// <summary>
487
+ /// The Version used by this entry.
488
+ /// </summary>
489
+ /// <remarks>
490
+ /// AE-1 iS 1. AE-2 is 2. With AE-2 no CRC is required and 0 is stored.
491
+ /// </remarks>
492
+ public enum VendorVersion : int
493
+ {
494
+ /// <summary>
495
+ /// Version AE-1.
496
+ /// </summary>
497
+ AE1 = 0x0001 ,
498
+
499
+ /// <summary>
500
+ /// Version AE-2.
501
+ /// </summary>
502
+ AE2 = 0x0002 ,
503
+ }
504
+
505
+ /// <summary>
506
+ /// Get the ID for this tagged data value.
507
+ /// </summary>
508
+ public ushort TagID => 0x9901 ;
509
+
510
+ /// <summary>
511
+ /// Set the data from the raw values provided.
512
+ /// </summary>
513
+ /// <param name="data">The raw data to extract values from.</param>
514
+ /// <param name="index">The index to start extracting values from.</param>
515
+ /// <param name="count">The number of bytes available.</param>
516
+ public void SetData ( byte [ ] data , int index , int count )
517
+ {
518
+ using ( MemoryStream ms = new MemoryStream ( data , index , count , false ) )
519
+ using ( ZipHelperStream helperStream = new ZipHelperStream ( ms ) )
520
+ {
521
+ //
522
+ // Unpack AES extra data field see http://www.winzip.com/aes_info.htm
523
+ var length = helperStream . Length ; // Data size currently 7
524
+ if ( length < 7 )
525
+ throw new ZipException ( "AES Extra Data Length " + length + " invalid." ) ;
526
+
527
+ int ver = helperStream . ReadLEShort ( ) ; // Version number (1=AE-1 2=AE-2)
528
+ int vendorId = helperStream . ReadLEShort ( ) ; // 2-character vendor ID 0x4541 = "AE"
529
+ int encrStrength = helperStream . ReadByte ( ) ; // encryption strength 1 = 128 2 = 192 3 = 256
530
+ int actualCompress = helperStream . ReadLEShort ( ) ; // The actual compression method used to compress the file
531
+
532
+ this . Version = ( VendorVersion ) ver ;
533
+ this . EncryptionStrength = ( byte ) encrStrength ;
534
+ this . CompressionMethod = ( CompressionMethod ) actualCompress ;
535
+ }
536
+ }
537
+
538
+ /// <summary>
539
+ /// Get the binary data representing this instance.
540
+ /// </summary>
541
+ /// <returns>The raw binary data representing this instance.</returns>
542
+ public byte [ ] GetData ( )
543
+ {
544
+ using ( MemoryStream ms = new MemoryStream ( ) )
545
+ using ( ZipHelperStream helperStream = new ZipHelperStream ( ms ) )
546
+ {
547
+ helperStream . IsStreamOwner = false ;
548
+
549
+ // Vendor ID is the two ASCII characters "AE".
550
+ const int VENDOR_ID = 0x4541 ; //not 6965;
551
+
552
+ // Pack AES extra data field see http://www.winzip.com/aes_info.htm
553
+ // extraData.AddLeShort(7); // Data size (currently 7)
554
+ helperStream . WriteLEShort ( ( int ) this . Version ) ; // Entry version
555
+ helperStream . WriteLEShort ( VENDOR_ID ) ; // "AE"
556
+ helperStream . WriteByte ( this . EncryptionStrength ) ; // 1 = 128, 2 = 192, 3 = 256
557
+ helperStream . WriteLEShort ( ( int ) this . CompressionMethod ) ; // The actual compression method used to compress the file
558
+
559
+ return ms . ToArray ( ) ;
560
+ }
561
+ }
562
+
563
+ /// <summary>
564
+ /// Get/set the <see cref="VendorVersion"> for this entry.</see>
565
+ /// </summary>
566
+ /// <remarks>
567
+ /// Defaults to 2 because we always use that when encrypting new entries.
568
+ /// </remarks>
569
+ public VendorVersion Version { get ; set ; } = VendorVersion . AE2 ;
570
+
571
+ /// <summary>
572
+ /// Get /set the real <see cref="CompressionMethod"> for this entry.</see>.
573
+ /// </summary>
574
+ public CompressionMethod CompressionMethod { get ; set ; }
575
+
576
+ /// <summary>
577
+ /// Get /set the encryption strength for this entry - 1 = 128 bit, 2 = 192 bit, 3 = 256 bit
578
+ /// </summary>
579
+ public byte EncryptionStrength { get ; set ; }
580
+ }
581
+
478
582
/// <summary>
479
583
/// A factory that creates <see cref="ITaggedData">tagged data</see> instances.
480
584
/// </summary>
0 commit comments