本文介绍了基于 本机特征信息(如CPU、主板、BIOS和MAC等) 的软件加密、授权与注册方法,并分享了 示例程序完整源代码。
目录
1 加密、授权与注册2 本机特征信息3 加密与解密算法4 软件授权检测5 示例程序5.1 界面设计5.2 模块代码5.3 完整代码下载
1 加密、授权与注册
软件的加密、授权与注册流程如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/e674af2cf3124a628495b26846d1fc97.png#pic_center)
2 本机特征信息
本机特征信息主要包括:①CPU信息、②主板序列号、③BIOS信息、④MAC地址,基于C#获取代码如下:
using System;
using System.Management;
using System.Net.NetworkInformation;
using Microsoft.Win32;
namespace RWRegister
{
public class Computer
{
public static string ComputerInfo()
{
string info = string.Empty;
string cpu = GetCPUInfo();
string baseBoard = GetBaseBoardInfo();
string bios = GetBIOSInfo();
string mac = GetMACInfo();
info = string.Concat(cpu, baseBoard, bios, mac);
return info;
}
private static string GetCPUInfo()
{
string info = string.Empty;
info = GetHardWareInfo("Win32_Processor", "ProcessorId");
return info;
}
private static string GetBaseBoardInfo()
{
string info = string.Empty;
info = GetHardWareInfo("Win32_BaseBoard", "SerialNumber");
return info;
}
private static string GetBIOSInfo()
{
string info = string.Empty;
info = GetHardWareInfo("Win32_BIOS", "SerialNumber");
return info;
}
private static string GetMACInfo()
{
string info = string.Empty;
info = GetMacAddressByNetwork();
return info;
}
private static string GetHardWareInfo(string typePath, string Key)
{
try
{
ManagementClass mageClass = new ManagementClass(typePath);
ManagementObjectCollection mageObjectColl = mageClass.GetInstances();
PropertyDataCollection Properties = mageClass.Properties;
foreach (PropertyData property in Properties)
{
if (property.Name == Key)
{
foreach (ManagementObject mageObject in mageObjectColl)
{
return mageObject.Properties[property.Name].Value.ToString();
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return string.Empty;
}
private static string GetMacAddressByNetwork()
{
string Key = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\";
string macAddress = string.Empty;
try
{
NetworkInterface[] Nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in Nics)
{
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet && adapter.GetPhysicalAddress().ToString().Length != 0)
{
string fRegistryKey = Key + adapter.Id + "\\Connection";
RegistryKey rKey = Registry.LocalMachine.OpenSubKey(fRegistryKey, false);
if (rKey != null)
{
string fPnpInstanceID = rKey.GetValue("PnpInstanceID", "").ToString();
int fMediaSubType = Convert.ToInt32(rKey.GetValue("MediaSubType", 0));
if (fPnpInstanceID.Length > 3 && fPnpInstanceID.Substring(0, 3) == "PCI")
{
macAddress = adapter.GetPhysicalAddress().ToString();
for (int i = 1; i |