5 changed files with 256 additions and 143 deletions
@ -0,0 +1,100 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Management; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 获取硬件SN
|
||||
|
/// </summary>
|
||||
|
internal class HardwareSN |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 获取cpuid
|
||||
|
/// </summary>
|
||||
|
public static string GetCPUSerialNumber() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor"); |
||||
|
string cpuSerialNumber = ""; |
||||
|
foreach (ManagementObject mo in searcher.Get()) |
||||
|
{ |
||||
|
cpuSerialNumber = mo["ProcessorId"].ToString().Trim(); |
||||
|
break; |
||||
|
} |
||||
|
return cpuSerialNumber; |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
return ""; |
||||
|
} |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取主板id
|
||||
|
/// </summary>
|
||||
|
public static string GetBIOSSerialNumber() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS"); |
||||
|
string biosSerialNumber = ""; |
||||
|
foreach (ManagementObject mo in searcher.Get()) |
||||
|
{ |
||||
|
biosSerialNumber = mo.GetPropertyValue("SerialNumber").ToString().Trim(); |
||||
|
break; |
||||
|
} |
||||
|
return biosSerialNumber; |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
return ""; |
||||
|
} |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取硬盘id
|
||||
|
/// </summary>
|
||||
|
public static string GetHardDiskSerialNumber() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia"); |
||||
|
string hardDiskSerialNumber = ""; |
||||
|
foreach (ManagementObject mo in searcher.Get()) |
||||
|
{ |
||||
|
hardDiskSerialNumber = mo["SerialNumber"].ToString().Trim(); |
||||
|
break; |
||||
|
} |
||||
|
return hardDiskSerialNumber; |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
return ""; |
||||
|
} |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取网卡id
|
||||
|
/// </summary>
|
||||
|
public static string GetNetCardMACAddress() |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))"); |
||||
|
string netCardMACAddress = ""; |
||||
|
foreach (ManagementObject mo in searcher.Get()) |
||||
|
{ |
||||
|
netCardMACAddress = mo["MACAddress"].ToString().Trim(); |
||||
|
break; |
||||
|
} |
||||
|
return netCardMACAddress; |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
return ""; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Security.Cryptography; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// MD5加密
|
||||
|
/// </summary>
|
||||
|
internal class MD5check |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 16位MD5加密
|
||||
|
/// </summary>
|
||||
|
/// <param name="password"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static string MD5Encrypt16(string password) |
||||
|
{ |
||||
|
var md5 = new MD5CryptoServiceProvider(); |
||||
|
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8); |
||||
|
t2 = t2.Replace("-", ""); |
||||
|
return t2; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 32位MD5加密
|
||||
|
/// </summary>
|
||||
|
/// <param name="password"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static string MD5Encrypt32(string password) |
||||
|
{ |
||||
|
string cl = password; |
||||
|
string pwd = ""; |
||||
|
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
|
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
|
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); |
||||
|
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
|
||||
|
for (int i = 0; i < s.Length; i++) |
||||
|
{ |
||||
|
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
||||
|
pwd = pwd + s[i].ToString("X"); |
||||
|
} |
||||
|
return pwd; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 64位MD5加密
|
||||
|
/// </summary>
|
||||
|
/// <param name="password"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static string MD5Encrypt64(string password) |
||||
|
{ |
||||
|
string cl = password; |
||||
|
//string pwd = "";
|
||||
|
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
|
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
|
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); |
||||
|
return Convert.ToBase64String(s); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 字符串转数字
|
||||
|
/// </summary>
|
||||
|
internal class StrToInt |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 十六进制字符串转十进制
|
||||
|
/// </summary>
|
||||
|
/// <param name="str">十六进制字符</param>
|
||||
|
/// <returns></returns>
|
||||
|
public static int To16Convert10(string str) |
||||
|
{ |
||||
|
int res = 0; |
||||
|
try |
||||
|
{ |
||||
|
str = str.Trim().Replace(" ", ""); //移除空字符
|
||||
|
//方法1
|
||||
|
res = int.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier); |
||||
|
//方法2
|
||||
|
//int r2 = System.Int32.Parse(str, System.Globalization.NumberStyles.HexNumber);
|
||||
|
//Console.WriteLine(r2);
|
||||
|
//方法3
|
||||
|
//int r3 = Convert.ToInt32(str, 16);
|
||||
|
//Console.WriteLine(r3);
|
||||
|
} |
||||
|
catch (Exception e) |
||||
|
{ |
||||
|
res = 0; |
||||
|
} |
||||
|
return res; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue