Generating Unique Key (Finger Print) for a Computer for Licensing Purposes
来源:互联网 发布:新手如何快速入门seo 编辑:程序博客网 时间:2024/06/03 02:35
原文链接:http://www.codeproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer
using System;using System.Management;using System.Security.Cryptography;using System.Security;using System.Collections;using System.Text;namespace Security{ /// <summary> /// Generates a 16 byte Unique Identification code of a computer /// Example: 4876-8DB5-EE85-69D3-FE52-8CF7-395D-2EA9 /// </summary> public class FingerPrint { private static string fingerPrint = string.Empty; public static string Value() { if (string.IsNullOrEmpty(fingerPrint)) { fingerPrint = GetHash("CPU >> " + cpuId() + "\nBIOS >> " + biosId() + "\nBASE >> " + baseId() + "\nDISK >> " + diskId() + "\nVIDEO >> " + videoId() + "\nMAC >> " + macId()); } return fingerPrint; } private static string GetHash(string s) { MD5 sec = new MD5CryptoServiceProvider(); ASCIIEncoding enc = new ASCIIEncoding(); byte[] bt = enc.GetBytes(s); return GetHexString(sec.ComputeHash(bt)); } private static string GetHexString(byte[] bt) { string s = string.Empty; for (int i = 0; i < bt.Length; i++) { byte b = bt[i]; int n, n1, n2; n = (int)b; n1 = n & 15; n2 = (n >> 4) & 15; if (n2 > 9) s += ((char)(n2 - 10 + (int)'A')).ToString(); else s += n2.ToString(); if (n1 > 9) s += ((char)(n1 - 10 + (int)'A')).ToString(); else s += n1.ToString(); if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-"; } return s; } #region Original Device ID Getting Code //Return a hardware identifier private static string identifier(string wmiClass, string wmiProperty, string wmiMustBeTrue) { string result = null; System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); System.Management.ManagementObjectCollection moc = mc.GetInstances(); foreach (System.Management.ManagementObject mo in moc) { if (mo[wmiMustBeTrue].ToString() == "True") { try { result = mo[wmiProperty].ToString(); break; } catch { } } } return result ?? string.Empty; } //Return a hardware identifier private static string identifier(string wmiClass, string wmiProperty) { string result = null; System.Management.ManagementClass mc = new System.Management.ManagementClass(wmiClass); System.Management.ManagementObjectCollection moc = mc.GetInstances(); foreach (System.Management.ManagementObject mo in moc) { try { result = mo[wmiProperty].ToString(); break; } catch { } } return result ?? string.Empty; } private static string cpuId() { //Uses first CPU identifier available in order of preference //Don't get all identifiers, as it is very time consuming string retVal = identifier("Win32_Processor", "UniqueId"); if (retVal.Length == 0) //If no UniqueID, use ProcessorID { retVal = identifier("Win32_Processor", "ProcessorId"); if (retVal.Length == 0) //If no ProcessorId, use Name { retVal = identifier("Win32_Processor", "Name"); if (retVal.Length == 0) //If no Name, use Manufacturer { retVal = identifier("Win32_Processor", "Manufacturer"); } //Add clock speed for extra security retVal += identifier("Win32_Processor", "MaxClockSpeed"); } } return retVal; } //BIOS Identifier private static string biosId() { return string.Concat(identifier("Win32_BIOS", "Manufacturer") , identifier("Win32_BIOS", "SMBIOSBIOSVersion") , identifier("Win32_BIOS", "IdentificationCode") , identifier("Win32_BIOS", "SerialNumber") , identifier("Win32_BIOS", "ReleaseDate") , identifier("Win32_BIOS", "Version")); } //Main physical hard drive ID private static string diskId() { return string.Concat(identifier("Win32_DiskDrive", "Model") , identifier("Win32_DiskDrive", "Manufacturer") , identifier("Win32_DiskDrive", "Signature") , identifier("Win32_DiskDrive", "TotalHeads")); } //Motherboard ID private static string baseId() { return string.Concat(identifier("Win32_BaseBoard", "Model") , identifier("Win32_BaseBoard", "Manufacturer") , identifier("Win32_BaseBoard", "Name") , identifier("Win32_BaseBoard", "SerialNumber")); } //Primary video controller ID private static string videoId() { return string.Concat(identifier("Win32_VideoController", "DriverVersion") , identifier("Win32_VideoController", "Name")); } //First enabled network card ID private static string macId() { return identifier("Win32_NetworkAdapterConfiguration", "MACAddress", "IPEnabled"); } #endregion }}
- Generating Unique Key (Finger Print) for a Computer for Licensing Purposes
- A FM for generating PASSWORD
- Systematic XACML request generation for testing purposes
- 【Java.Concurrency】多线程的代价 & Why Threads Are A Bad Idea (for most purposes)
- Cross finger for my weblog.
- Jinja2 example for generating a local file using a template
- how to print log for a developer
- A Hierarchical Latent Variable Encoder-Decoder Model for Generating Dialogues
- (reading)A Hierarchical Approach for Generating Descriptive Image Paragraphs
- finger print GUI
- Generating SSH keys for github
- Generating SSH keys for github
- generating selection dmat for igllib
- CSS for window.print()
- Power Provisioning for a Warehouse-sized Computer(总结)
- is the Tao in the DOS for a personal computer
- A curated list of deep learning resources for computer vision
- Mathematics for Computer Graphics
- QThread架构中QObject间通讯常见误区澄清
- how to use Dom to create and remove element
- 大数阶乘思考
- C中.h头文件的写法
- 进程池实现客户端连接请求程序
- Generating Unique Key (Finger Print) for a Computer for Licensing Purposes
- epoll()学习
- SQL union用法
- 程序设计的SOLID原则
- 11第三个放个假低功耗
- 动态规划入门三---背包问题(1)
- [Leetcode] Word Break、Word BreakII
- 好用的同步代码块和同步函数
- 语法错误javac(编译),逻辑错误java(运行)