using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Management; using System.Text; using System.Threading.Tasks; using System.Xml; namespace OTSMeasureApp { class CRegistration { public bool RegistrationVerification() { try { if (!checkRegistration())//文件授权法 { return false; } //狗加密法 //SenseShield.DogDecrypting.decrypting(101);//参数为许可号 } catch (Exception ex) { return false; } return true; } private bool checkRegistration() { string CPUID, DiskID; CPUID = getCpu(); DiskID = GetDiskVolumeSerialNumber(); var ID = ReadXML("./Config/SysData/RegistrationProofreading.txt"); if (ID.Count == 0) { return false; } List list_str = new List(); List list_time = new List(); ID.TryGetValue("ID", out list_str); ID.TryGetValue("Time", out list_time); string setCPU = ConvertString(list_str[0]); string setDisk = ConvertString(list_str[1]); string setYear = ConvertString(list_time[0]); string setMonth = ConvertString(list_time[1]); string setDay = ConvertString(list_time[2]); if (CPUID != setCPU || DiskID != setDisk) { return false; } DateTime dt = DateTime.ParseExact(setYear + setMonth + setDay + "235959", "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture); if (DateTime.Now > dt) { return false; } return true; } // 获得CPU的序列号 private static string getCpu() { string strCpu = null; ManagementClass myCpu = new ManagementClass("win32_Processor"); ManagementObjectCollection myCpuConnection = myCpu.GetInstances(); foreach (ManagementObject myObject in myCpuConnection) { strCpu = myObject.Properties["Processorid"].Value.ToString(); break; } return strCpu; } // 取得设备硬盘的卷标号 private static string GetDiskVolumeSerialNumber() { ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\""); disk.Get(); return disk.GetPropertyValue("VolumeSerialNumber").ToString(); } private static IDictionary> ReadXML(string address) { IDictionary> infos = new Dictionary>(); if (File.Exists(address)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(address); XmlNode xn = xmlDoc.SelectSingleNode("infos"); XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xnf in xnl) { XmlElement xe = (XmlElement)xnf; XmlNode nameNode = xe.SelectSingleNode("ID"); string name = nameNode.InnerText; Console.WriteLine(name); XmlNode filelist = xe.SelectSingleNode("filelist"); List list = new List(); foreach (XmlNode item in filelist.ChildNodes) { list.Add(item.InnerText); } infos.Add(name, list); } } return infos; } private string ConvertString(string str) { string str_out; string[] arr = str.Split(','); byte[] be = new byte[arr.Count()]; for (int i = 0; i < arr.Count(); i++) { be[i] = Convert.ToByte(arr[i]); } str_out = Encoding.Unicode.GetString(be); return str_out; } } }