PowerTCP Zip Compression for .NET
Encryption



Items in an archive can be encrypted during the zipping process by specifying an encryption type (Encryption) and a password (ArchiveItem.Password). If an item's password or encryption type is not explicitly set, the archive's default properties will be used (DefaultEncryption and Password, respectively). When explicitly set, an item's properties will always be used, regardless of when the archive's default properties are set. The same properties can be set to decrypt items in a compressed archive prior to decompression. Please note that the AES encryption implemented in PowerTCP Zip Compression for .NET is designed to be compatible with WinZip.

Note that it is no longer necessary to distribute the Dart.PowerTCP.Aes.dll, as it is now a resource embedded in the Dart.PowerTCP.Zip.dll.

Encrypting items in an archive

  1. Add the Archive component to a new form.
  2. Add a button to the form.
  3. Add items to the archive.
  4. Set the Archive level properties.
  5. Zip the archive. The first and second items will be encrypted. The second item will use the Archive values.
  6. For demonstration purposes, explicitly set the second item and change Password. When the archive is zipped again, none of the items will use the new archive password.
C#
Copy Code
//Add an item with Standard Encryption and a Password
ArchiveItem item1 = new ArchiveItem("c:\\Test\\file1.txt");
item1.Encryption = Encryption.Standard;
item1.Password = "lothlorien";
archive1.Add(item1);
//Add an item that will use the archive's defaults
archive1.Add("c:\\Test\\file2.jpg");
//Add a non-encrypted item to archive - this item will not use the defaults
ArchiveItem item3 = new ArchiveItem("c:\\Test\\file3.doc");
item3.Encryption = Encryption.None;
item3.Password = "not used"; //Not used, since there is no encryption
archive1.Add(item3);
// Set default encryption and password for archive
// Only the second item will use these values
archive1.DefaultEncryption = Encryption.Standard;
archive1.Password = "hobbiton";
// Name | Password | Encryption
// -----------------------------------
// file1.txt | lothlorien | Standard
// file2.jpg | hobbiton | Standard
// file3.doc | not used | None
archive1.Zip("c:\\test.zip");
// Explicitly set password of second item
archive1[1].Password = "rivendell";
//Set default encryption and password for archive
//This time, none of the items will use the defaults when zipped
archive1.DefaultEncryption = Encryption.Standard;
archive1.Password = "khazad-dum";
// Name | Password | Encryption
// file1.txt | lothlorien | Standard
// file2.jpg | rivendell | Standard
// file3.doc | not used | None
archive1.Zip("c:\\Test\\test.zip");
Visual Basic
Copy Code
' Add an item with Standard Encryption and a Password
Dim item1 As New ArchiveItem("c:\Test\file1.txt")
item1.Encryption = Standard
item1.Password = "lothlorien"
archive1.Add(item1)
' Add an item that will use the archive's defaults
archive1.Add("c:\Test\file2.jpg")
' Add a non-encrypted item to archive - this item will not use the defaults
Dim item3 As New ArchiveItem("c:\Test\file3.doc")
item3.Encryption = None
item3.Password = "not used" ' Not used, since there is no encryption
archive1.Add(item3)
' Set default encryption and password for archive
' Only the second item will use these values
archive1.DefaultEncryption = Standard
archive1.Password = "hobbiton"
' Name | Password | Encryption
' -----------------------------------
' file1.txt | lothlorien | Standard
' file2.jpg | hobbiton | Standard
' file3.doc | not used | None
Archive1.Zip("c:\test.zip")
' Explicitly set password of second item
archive1(1).Password = "rivendell"
' Set default encryption and password for archive
' This time, none of the items will use the defaults when zipped
archive1.DefaultEncryption = Standard
archive1.Password = "khazad-dum"
' Name | Password | Encryption
' file1.txt | lothlorien | Standard
' file2.jpg | rivendell | Standard
' file3.doc | not used | None
archive1.Zip("c:\Test\test.zip")

Decrypting items in an archive

  1. Add the Archive component to a new form. For instructions on how to do this see, "Creating An Instance Of A Component Using Visual Studio .NET."
  2. Add a button to the form.
  3. Open an archive with encrypted items
  4. If all items in the archive use the same password, the Archive properties can be set prior to unzipping.
  5. If individual items have different passwords, the ArchiveItem properties can be set prior to unzipping.
  6. Unzip the archive.
C#
Copy Code
archive1.Add("c:\\Test\\*.txt");
//This archive will always extract to the Test directory. By default, existing files
//will be overwritten, but this can be changed by the end-user
archive1.SelfExtractConfiguration = new SelfExtractConfiguration("This is my self-extracting archive!",
    "c:\\Test", false, Overwrite.Always, true, true, true, archive1.Encoding.CodePage, SelfExtractBehavior.UserInteractive, "");
archive1.Zip("c:\\mySelfExtractingArchive.exe");
Visual Basic
Copy Code
Archive1.Add("c:\Test\*.txt")
'This archive will always extract to the Test directory. By default, existing files
'will be overwritten, but this can be changed by the end-user
Archive1.SelfExtractConfiguration = New SelfExtractConfiguration("This is my self-extracting archive!", _
    "c:\Test", False, Overwrite.Always, True, True, True, Archive1.Encoding.CodePage, SelfExtractBehavior.UserInteractive, "")
Archive1.Zip("c:\mySelfExtractingArchive.exe")

PowerTCP Zip for .NET Documentation Version 2.1.1
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic