none
Reading Data from a Password protected Zip File. RRS feed

  • Question

  • Hi, I am trying to read data from a Password Protected Zip file.

    The password of Demo.Zip is 12345 and I want to read the content inside Demo.zip which is a text file having to contain comma-separated values

    Here's my code - 

    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.IO.Compression;
    using Ionic.Zip;
    
    namespace CSVDemoApplication
    {
        class Program
        {
            Dictionary<string, float> CSVReader = new Dictionary<string, float>();
    
            public void ReadCSVFile(string path)
            {
                using (Ionic.Zip.ZipFile archive = new Ionic.Zip.ZipFile(path))
                {
                    archive.Password = "12345";
                    archive.Encryption = EncryptionAlgorithm.WinZipAes128;
    
                    foreach (ZipEntry entry in archive)
                    {
                        string[] read;
                        char[] seperators = { ',' };
                        StreamReader reader = new StreamReader(entry.OpenReader("12345"));
                        string data = "";
    
                        while ((data = reader.ReadLine()) != null)
                        {
                            read = data.Split(seperators, StringSplitOptions.None);
                            var newKey = read[0];
                            var newValue = float.Parse(read[1]);
                            CSVReader[newKey] = newValue;
                        }
                    }
                }
            }
    
            public void PrintCSVValues()
            {
                foreach (KeyValuePair<string, float> item in CSVReader)
                {
                    Console.WriteLine(item.Key + " - " + item.Value);
                }
    
            }
    
            static void Main(string[] args)
            {
                Program p = new Program();
                string path = @"D:\Projects\VS Projects\2019\CSharp\CSVDemoApplication\Demo.zip";
                p.ReadCSVFile(path);
                p.PrintCSVValues();
                Console.ReadLine();
            }
        }
    }

    I have tried reading the text.zip file which does not have any password and I can retrieve the Data from the text.txt. So, Is there a way to retrieve data from the Password protected Demo.zip knowing the password is 12345, Please Help.




    • Edited by slalithp Thursday, October 24, 2019 1:15 PM Edited
    • Moved by CoolDadTx Thursday, October 24, 2019 1:47 PM Third party product
    Thursday, October 24, 2019 1:11 PM

Answers

  • You are using the third party library for the file. We do not provide support for third party products in these forums. You will need to post your question in their forums. The NuGet package doesn't link to anything but it appears it is also part of DotNetZip so you might start there.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by slalithp Friday, October 25, 2019 3:58 AM
    Thursday, October 24, 2019 1:47 PM

All replies

  • You are using the third party library for the file. We do not provide support for third party products in these forums. You will need to post your question in their forums. The NuGet package doesn't link to anything but it appears it is also part of DotNetZip so you might start there.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by slalithp Friday, October 25, 2019 3:58 AM
    Thursday, October 24, 2019 1:47 PM
  • Okay, Thank you. 
    Friday, October 25, 2019 3:58 AM