/// <summary> /// 获得机器码 /// </summary> /// <returns></returns> public static string GetMachineCode() { string s = ""; byte[] macAddress = Win32Util.GetMacAddress(); for (int i = 0; i < macAddress.Length; i++) { s = s + macAddress[i].ToString(); } ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_BIOS"); foreach (ManagementObject obj2 in searcher.Get()) { s = s + obj2["Name"]; s = s + obj2["BuildNumber"]; s = s + obj2["Manufacturer"]; s = s + obj2["SMBIOSBIOSVersion"]; } byte[] bytes = new UnicodeEncoding().GetBytes(s); long hash = 0L; TeaEncrypt.TeaHash2(bytes, bytes.Length, out hash); bytes = BitConverter.GetBytes(hash); return(string.Format("{0,2:X}{1,2:X}-{2,2:X}{3,2:X}-{4,2:X}{5,2:X}-{6,2:X}{7,2:X}", new object[] { bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7] }).Replace('O', 'P').Replace('L', 'A').Replace('I', 'C').Replace('1', 'Z').Replace(' ', 'K')); }
/// <summary> /// 获得注册码 /// </summary> /// <param name="_username">授权用户</param> /// <param name="_domainname">授权域名,为空表示域名不受限制,多个域名用分号</param> /// <param name="_machinecode">机器码</param> /// <returns></returns> public static string GetSerialCode(string _username, string _domainname, string _machinecode) { long num; string s = _username + "," + _domainname + "," + _machinecode.ToUpper(); byte[] bytes = new UnicodeEncoding().GetBytes(s); TeaEncrypt.TeaHash2(bytes, bytes.Length, out num); byte[] buffer2 = BitConverter.GetBytes(num); return(string.Format("{0,2:X}{1,2:X}-{2,2:X}{3,2:X}-{4,2:X}{5,2:X}-{6,2:X}{7,2:X}", new object[] { buffer2[0], buffer2[1], buffer2[2], buffer2[3], buffer2[4], buffer2[5], buffer2[6], buffer2[7] }).Replace('O', 'F').Replace('L', 'Y').Replace('I', 'X').Replace('1', 'B').Replace(' ', 'A')); }