使用winrar解压如何检查密码

本文关键字:检查 密码 何检查 winrar 使用 | 更新日期: 2023-09-27 18:29:41

使用winrar解压,如何检测密码是否正确?

the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE'Microsoft'Windows'CurrentVersion'App Paths'WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_Info = "x " + rarName + " " + _unRarPath + " -y -p123456";
ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = _rarPath;//获取压缩包路径
Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();

使用winrar解压如何检查密码

我希望这个解决方案能对您有所帮助。这是链接的原始帖子

public class ZipPasswordTester
 {
    public bool CheckPassword(Ionic.Zip.ZipEntry entry, string password)
    {
      try
       {
           using (var s = new PasswordCheckStream())
           {
            entry.ExtractWithPassword(s, password);
          }
        return true;
      }
    catch (Ionic.Zip.BadPasswordException)
    {
        return false;
    }
    catch (PasswordCheckStream.GoodPasswordException)
    {
        return true;
    }
}
  private class PasswordCheckStream : System.IO.MemoryStream
  {
       public override void Write(byte[] buffer, int offset, int count)
      {
        throw new GoodPasswordException();
       }
    public class GoodPasswordException : System.Exception { }
     }
  }