问题
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