在开发应用软件的时候比较多的情况下会要求生成一个唯一的代码来确定是那个设备的相关数据,这里举例的环境为Windows 操作系统下的生成唯一代码的方法。
参与计算的硬件资源ID有 CPUID,主板ID和内存ID;具体样例代码如下:
/// <summary>
/// 获取传感器ID(16位HASH代码)
/// </summary>
/// <returns></returns>
private static string GetSensorID()
{
string sensorID = string.Empty;
string basicID = GetCPUID() + GetMotherboardID() + GetPhysicalMemoryID();
System.Security.Cryptography.MD5CryptoServiceProvider mD5CryptoServiceProvider = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hashedBuff = mD5CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(basicID));
for (int i = 4; i < 12; i++)
{
sensorID += hashedBuff[i].ToString("