G
G
Grigory Boev2019-11-09 20:01:29
Character encoding
Grigory Boev, 2019-11-09 20:01:29

How to use Russian characters in zip password in Ionic.Zip?

Good afternoon. There was a task - to use zip files in the program on c#. I need password support when unzipping, so I installed Ionic.Zip.
The code is like this:

using Ionic.Zip;
using System;
using System.IO;
using System.Text;

namespace zipExtractor
{
 class Program
    {
  static void Main(string[] args)
        {
      var isDebugMode = true;
    
            var zipFileName = "archive.zip";
            var passWord = "password";
            var filesList = "1.txt";

      //magic

      using (ZipFile zip = ZipFile.Read(zipFileName, new ReadOptions { Encoding = Encoding.GetEncoding("cp866") }))
            {
                foreach (ZipEntry e in zip)
                {
                    if (e.FileName==filesList)
                    {
                        
                        e.ExtractWithPassword(ExtractExistingFileAction.OverwriteSilently, passWord);
                        if (isDebugMode)
                        {
                            Console.WriteLine($"{e.FileName}");
                        }
                    }
                }
            }
      Console.ReadKey();
        }
    }
}

Tested on different archives. If there are Russian characters in the archive, then Ionic.Zip.BadPasswordException : "bad password" , i.e. Incorrect password. I looked at how the password is encoded through Advanced Archive Password Recovery, the password " password " was displayed as " 43f 430 440 43e 43b 44c ", i.e. unicode.
I tried to convert the string before unzipping, did not help. How to overcome it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-11-10
@yarosroman

Convert the string to ascii before use, here, https://social.msdn.microsoft.com/Forums/vstudio/e...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question