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.
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") |
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") |