C# NUnrar library (extracting password protected rar files without password)

▼魔方 西西 提交于 2019-12-02 04:39:42

问题


I am using this library in C# to extract RAR files.

http://nunrar.codeplex.com/

Is it able to extract a file even if it is password protected? It doesn't even ask for password. How is that possible?

I am creating RAR files using WinRar and putting password on them.


回答1:


I'm the author of nunrar and https://sharpcompress.codeplex.com/

I am making decryption of password protected rar archives my next item to do as I thought I had already done it (zip files blurred my memory).

As another comment said, I am always looking for help but hopefully I'll get this done soon.




回答2:


(End of Year 2018.) Solution for unpacking RAR (4 or 5 format) archive with Password: Install Nuget Packages 7z.Libs (https://www.nuget.org/packages/7z.Libs/) and Squid-Box.SevenZipSharp (https://www.nuget.org/packages/Squid-Box.SevenZipSharp/). Using this code: (edit: error correction)

        public void Unpack()
        {
            var rawBytes = File.ReadAllBytes(".\\Some.rar");

            using (var stream = new MemoryStream(rawBytes, true))
            {
                // Toggle between the x86 and x64 bit dll
                var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, Environment.Is64BitProcess ? "x64" : "x86", "7z.dll");
                SevenZip.SevenZipBase.SetLibraryPath(path);

                using (var outMemStream = File.Create(".\\SomeSingleFile.txt"))
                {
                    var extractor = new SevenZipExtractor(stream, "passwordXXX");
                    var entry = extractor.ArchiveFileData.Single(info => false == info.IsDirectory);    
                    extractor.ExtractFile(entry.Index, outMemStream);                        
                }
            }
        }


来源:https://stackoverflow.com/questions/9963611/c-sharp-nunrar-library-extracting-password-protected-rar-files-without-password

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!