C#生成软件注册码

C#⽣成软件注册码
C# ⽣成软件注册码
今天早上,花了⼀个早上弄了个⽣成机器码和注册码的Demo,通过⽣成的注册码⾥⾯包含时间信息,保证了注册码在使⽤后的指定时间后失效
由于数学不⾏所以写的⽐较简单,ok 上代码吧
1. 产⽣机器码的原理很简单,基本上都是取设备信息之后加密
/// <summary>
/// 取本机机器码
/// </summary>
展频原理public static string GetMachineCode()
{
//CPU信息
string cpuId = DeviceHelper.GetCpuID();
//磁盘信息
string diskId = DeviceHelper.GetDiskID();
//⽹卡信息
string MacAddress = DeviceHelper.GetMacAddress();
string m1 = GetMD5(cpuId + typeof(string).ToString());
string m2 = GetMD5(diskId + typeof(int).ToString());
string m3 = GetMD5(MacAddress+typeof(double).ToString());
string code1 = GetNum(m1, 8);
string code2 = GetNum(m2, 8);
string code3 = GetNum(m3, 8);
return code1 + code2 + code3;
}
1. 产⽣注册码
物理教具制作
/// 根据机器码产⽣注册码
/// </summary>
/// <param name="machineCode">机器码</param>
/// <param name="overTime">到期时间</param>
/// <returns></returns>
public static string CreateRegisterCode(string machineCode,DateTime overTime)        {
int year = int.Parse(overTime.Year.ToString().Substring(2))+33;
int month = overTime.Month+21;
int day = overTime.Day+54;
int section = machineCode.Length / 4;
string reg = "";
int n = 1597;
for (int i = 0; i < section; i++)
{
比例电磁铁
int sec = int.Parse(machineCode.Substring(i*4,4));
int resu = sec + n;
if (resu >= 10000)
{
resu = sec - 1597;
}
reg += resu ;
n = n + 1597;
}
//插⼊年⽉⽇信息
reg = InsertNum(reg, year, 0, 8, 4, 6, 7, 1, 3, 2, 5, 9);
reg = InsertNum(reg, month, 0, 6, 9, 7, 3, 8, 4, 1, 2, 5);
reg = InsertNum(reg, day, 0,1, 2, 5, 6,7, 3, 8,  9, 4);
return reg.ToString();
}
/// <summary>
/
// 在指定数字后⾯插⼊内容
/// </summary>
/// <param name="str"></param>
/// <param name="num"></param>短信支付平台
地能空调/// <param name="index"></param>
/// <param name="pmc"></param>
/// <returns></returns>
static string InsertNum(string str,int num,int index,params int[] pmc)        {
int posi = str.IndexOf(pmc[index].ToString());
if (posi <= -1)
return InsertNum(str, num, index + 1, pmc);
return str.Insert(posi, num.ToString());
}
1. 验证注册码
/// 检查注册码
/// </summary>
/// <param name="registerCode"></param>
/// <param name="overTime"></param>
/// <returns></returns>
public static bool CheckRegister( string registerCode,ref DateTime overTime)        {
try
{
string machineCode = GetMachineCode();
//提取年⽉⽇
int day = int.Parse(ExtractNum(ref registerCode, 0, 1, 2, 5, 6, 7, 3, 8, 9, 4));
int month = int.Parse(ExtractNum(ref registerCode, 0, 6, 9, 7, 3, 8, 4, 1, 2, 5));
int year = int.Parse(ExtractNum(ref registerCode, 0, 8, 4, 6, 7, 1, 3, 2, 5, 9));
day -= 54;
month -= 21;
year -= 33;
overTime = new DateTime(year, month, day);
//核对注册码
int section = machineCode.Length / 4;
int n = 1597;
string reg = "";
for (int i = 0; i < section; i++)
{
int sec = int.Parse(machineCode.Substring(i * 4, 4));
int resu = sec + n;
if (resu >= 10000)
{
resu = sec - 1597;
}
reg += resu;
n = n + 1597;
}
return registerCode == reg;
}
catch {
return false;
}
}
/// <summary>
/// 提取数字
/// </summary>
/
// <param name="str"></param>
/// <param name="index"></param>
/// <param name="pmc"></param>
/// <returns></returns>应力测试
static string ExtractNum(ref string str, int index, params int[] pmc)
{
int posi = str.IndexOf(pmc[index].ToString());
if (posi <= -1)
return ExtractNum(ref str, index + 1, pmc);
string resu = str.Substring(posi - 2, 2);
str = str.Remove(posi - 2, 2);
return resu;
}
1. 调⽤实例
//取机器码
string mCode = RegInfo.GetMachineCode();
//产⽣注册码
string regCode = RegInfo.CreateRegisterCode(mCode, DateTime.Now);
DateTime time = DateTime.Now;
//验证注册码
bool resu = RegInfo.CheckRegister(regCode+"1", ref time);
代码下载

本文发布于:2024-09-22 13:35:41,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/105931.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:注册码   信息   时间   机器码   原理   包含   保证
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议