using HL_FristAidPlatform_Public; using System; using System.IO; using System.Management; using System.Security.Cryptography; using System.Text; namespace HL_FristAidPlatform_Frame { class DecryptHelper { private static string ComputerInfofile = @"D:\ComputerInfo.key"; private static string RegistInfofile = @"D:\RegistInfo.key"; public static bool CheckRegist(string key) { return CheckRegistData(key); } private static bool CheckRegistData(string key) { if (ExistRegistInfofile() == false) { return false; } else { string info = ReadFile(RegistInfofile); string computer = ReadFile(ComputerInfofile); string registData = Decrypt(info, "JKKJYXGS"); string[] reg = registData.Split(','); if (computer == reg[0] && Information.Hospital.Name == reg[1] && DateTime.Now < Convert.ToDateTime(reg[2])) { return true; } else { return false; } } } public static bool ExistRegistInfofile() { return File.Exists(RegistInfofile); } public static string ReadRegistFile() { return ReadFile(RegistInfofile); } private static string ReadFile(string fileName) { string info = string.Empty; try { using (StreamReader sr = new StreamReader(fileName)) { info = sr.ReadToEnd(); sr.Close(); } } catch (Exception) { } return info; } private static string Decrypt(string pToDecrypt, string sKey) { MemoryStream ms = new MemoryStream(); try { DESCryptoServiceProvider des = new DESCryptoServiceProvider(); byte[] inputByteArray = new byte[pToDecrypt.Length / 2]; for (int x = 0; x < pToDecrypt.Length / 2; x++) { int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16)); inputByteArray[x] = (byte)i; } des.Key = Encoding.ASCII.GetBytes(sKey); des.IV = Encoding.ASCII.GetBytes(sKey); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); StringBuilder ret = new StringBuilder(); } catch (Exception ex) { PublicClass.WriteErrorLog("DecryptHelper", "Decrypt:\r\n" + ex); } return Encoding.Default.GetString(ms.ToArray()); } public static string GetComputerInfo() { string info = string.Empty; string cpu = GetHardWareInfo("Win32_Processor", "ProcessorId"); string bios = GetHardWareInfo("Win32_BIOS", "SerialNumber"); string mac = GetHardWareInfo("Win32_BaseBoard", "SerialNumber"); info = string.Concat(cpu, bios, mac); return info; } private static string GetHardWareInfo(string typePath, string key) { try { ManagementClass managementClass = new ManagementClass(typePath); ManagementObjectCollection mn = managementClass.GetInstances(); PropertyDataCollection properties = managementClass.Properties; foreach (PropertyData property in properties) { if (property.Name == key) { foreach (ManagementObject m in mn) { return m.Properties[property.Name].Value.ToString(); } } } } catch (Exception) { } return string.Empty; } } }