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