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
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?
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();
}
}
}