源码
链接:https://pan.baidu.com/s/1FviJKDn5FQQH9nujBCO9mA
提取码:0adr
源码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Security.Cryptography;
namespace RegistrationCode
{
public partial class Form1 : Form
{
// 私钥
private static readonly string PrivateKey = "https://mirror.baidu.com/pypi/simple";
public Form1()
{
InitializeComponent();
}
// 获取主板编号
private void btnGetCode_Click(object sender, EventArgs e)
{
string mbsn = Utility.getMBSN();
this.tbMbsn.Text = mbsn;
}
// 计算注册码
private void btnCalcCode_Click(object sender, EventArgs e)
{
string enterString = this.tbMbsn.Text + PrivateKey;
string rgisterCode = Utility.Sha1(enterString);
this.tbRgisterCode.Text = rgisterCode;
}
}
public class Utility
{
//主板序列号
public static string getMBSN()
{
//获取主板序列号
string mbsn = "";
ManagementClass mc = new ManagementClass("win32_baseboard");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
mbsn = mo.Properties["SerialNumber"].Value.ToString();
break;
}
return mbsn;
}
// SHA1 加密
private static readonly Encoding Encoder = Encoding.UTF8;
public static String Sha1(String content)
{
try
{
SHA1 sha1 = new SHA1CryptoServiceProvider(); // 创建SHA1对象
byte[] bytes_in = Encoder.GetBytes(content); // 将待加密字符串转为byte类型
byte[] bytes_out = sha1.ComputeHash(bytes_in); // Hash运算
sha1.Dispose(); // 释放当前实例使用的所有资源
String result = BitConverter.ToString(bytes_out); // 将运算结果转为string类型
result = result.Replace("-", "").ToUpper();
return result;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}