RarArchiveLoadOptions.DecryptionPassword

RarArchiveLoadOptions.DecryptionPassword property

获取或设置用于解密条目和条目名称的密码。

public string DecryptionPassword { get; set; }

例子

您可以在存档提取时提供一次解密密码。

using (FileStream fs = File.OpenRead("encrypted_archive.rar"))
{
    using (var extracted = File.Create("extracted.bin"))
    {
        using (RarArchive archive = new RarArchive(fs, new ArchiveLoadOptions() { DecryptionPassword = "p@s$" }))
        {
            using (var decompressed = archive.Entries[0].Open())
            {
                byte[] b = new byte[8192];
                int bytesRead;
                while (0 < (bytesRead = decompressed.Read(b, 0, b.Length)))
                    extracted.Write(b, 0, bytesRead);
                
            }
        }
    }
}

也可以看看