jpfileHelp.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Web;
  3. namespace Ant.Service.Utilities
  4. {
  5. /// <summary>
  6. /// jpfile.exe调用
  7. /// </summary>
  8. public static class jpfileHelp
  9. {
  10. /// <summary>
  11. /// 文件加解密
  12. /// </summary>
  13. /// <param name="oFileName">原文件地址</param>
  14. /// <param name="EncodeOrDecode">加密或解密参数,如:-d、-f</param>
  15. /// <param name="Password">密码</param>
  16. /// <returns></returns>
  17. public static bool FileCrypt(string oFileName, string EncodeOrDecode, string Password)
  18. {
  19. string jpfile = HttpContext.Current.Server.MapPath("~/DLL/tools/jpfile.exe");
  20. if ((!System.IO.File.Exists(jpfile)) || (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(oFileName))))
  21. {
  22. return false;
  23. }
  24. oFileName = HttpContext.Current.Server.MapPath(oFileName);
  25. string Command = EncodeOrDecode + " \"" + oFileName + "\" \"" + Password + "\"";
  26. System.Diagnostics.Process p = new System.Diagnostics.Process();
  27. p.StartInfo.FileName = jpfile;
  28. p.StartInfo.Arguments = Command;
  29. p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/DLL/");
  30. p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序 启动 线程
  31. //p.StartInfo.RedirectStandardInput = true;
  32. //p.StartInfo.RedirectStandardOutput = true;
  33. p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,jpfile的所有输出信息,都为错误输出流,用 StandardOutput是捕获不到任何消息的...
  34. p.StartInfo.CreateNoWindow = false;//不创建进程窗口
  35. p.Start();//启动线程
  36. p.BeginErrorReadLine();//开始异步读取
  37. p.WaitForExit();//等待完成
  38. //p.StandardError.ReadToEnd();//开始同步读取
  39. p.Close();//关闭进程
  40. p.Dispose();//释放资源
  41. return true;
  42. }
  43. /// <summary>
  44. /// 加解密密码。默认密码是12345678
  45. /// </summary>
  46. /// <param name="oFileName"></param>
  47. /// <param name="EncodeOrDecode"></param>
  48. /// <returns></returns>
  49. public static bool FileCrypt(string oFileName, string EncodeOrDecode)
  50. {
  51. return FileCrypt(oFileName, EncodeOrDecode, "12345678");
  52. }
  53. /// <summary>
  54. /// 加密文件。默认密码是12345678
  55. /// </summary>
  56. /// <param name="oFileName"></param>
  57. /// <returns></returns>
  58. public static bool FileCrypt(string oFileName)
  59. {
  60. return FileCrypt(oFileName, "-d", "12345678");
  61. }
  62. }
  63. }