/trunk/ldjReg/Form1.cs

https://gitlab.com/BGCX261/zhuanlidm-svn-to-git · C# · 89 lines · 77 code · 4 blank · 8 comment · 2 complexity · 09129e425bebac11165962a775f1ba8c MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Security.Cryptography;
  9. using System.IO;
  10. using System.Diagnostics;
  11. namespace ldjReg
  12. {
  13. public partial class Form1 : Form
  14. {
  15. private Dm.dmsoft dm;
  16. private const string key = "LuDingJi";
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. RunReg("RegDll.dll /s");
  21. RunReg("dm.dll /s");
  22. RunReg("eyou.dll /s");
  23. dm = new Dm.dmsoft();
  24. if (dm.Ver() == "")
  25. {
  26. MessageBox.Show("Can't Create Object dm.dmsoft");
  27. }
  28. }
  29. public void RunReg(string cmd)
  30. {
  31. ProcessStartInfo pi = new ProcessStartInfo("regsvr32.exe");
  32. pi.Arguments = cmd;
  33. pi.CreateNoWindow = true;
  34. pi.RedirectStandardError = false;
  35. pi.RedirectStandardInput = false;
  36. pi.RedirectStandardOutput = false;
  37. pi.UseShellExecute = false;
  38. Process p = new Process();
  39. p.StartInfo = pi;
  40. p.Start();
  41. p.WaitForExit();
  42. p.Close();
  43. }
  44. /// <summary>
  45. /// DES加密算法
  46. /// sKey为8位或16位
  47. /// </summary>
  48. /// <param name="pToEncrypt">需要加密的字符串</param>
  49. /// <param name="sKey">密钥</param>
  50. /// <returns></returns>
  51. public string DE(string pToEncrypt, string sKey)
  52. {
  53. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  54. byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
  55. des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  56. des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  57. MemoryStream ms = new MemoryStream();
  58. CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
  59. cs.Write(inputByteArray, 0, inputByteArray.Length);
  60. cs.FlushFinalBlock();
  61. StringBuilder ret = new StringBuilder();
  62. foreach (byte b in ms.ToArray())
  63. {
  64. ret.AppendFormat("{0:X2}", b);
  65. }
  66. ret.ToString();
  67. return ret.ToString();
  68. //return a;
  69. }
  70. public string DCode(string mCode, string key)
  71. {
  72. string dCode = "";
  73. char[] mCodeL = mCode.ToCharArray();
  74. char tmp = mCodeL[1];
  75. mCodeL[1] = mCodeL[mCodeL.Length - 2];
  76. mCodeL[mCodeL.Length - 2] = tmp;
  77. dCode = DE(new string(mCodeL), key);
  78. return dCode;
  79. }
  80. private void btnCreateRegCode_Click(object sender, EventArgs e)
  81. {
  82. this.txtRegCode.Text = DCode(this.txtMCode.Text.Trim(), key);
  83. }
  84. }
  85. }