C# 生成软件注册码
来源:互联网 发布:高新区行知小学好不好 编辑:程序博客网 时间:2024/05/16 18:51
C# 生成软件注册码
今天早上,花了一个早上弄了个生成机器码和注册码的Demo,通过生成的注册码里面包含时间信息,保证了注册码在使用后的指定时间后失效
由于数学不行所以写的比较简单,ok 上代码吧
- 产生机器码的原理很简单,基本上都是取设备信息之后加密
/// <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; }
- 产生注册码
/// <summary> /// 根据机器码产生注册码 /// </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()); }
- 验证注册码
/// <summary> /// 检查注册码 /// </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; }
- 调用实例
//取机器码 string mCode = RegInfo.GetMachineCode(); //产生注册码 string regCode = RegInfo.CreateRegisterCode(mCode, DateTime.Now); DateTime time = DateTime.Now; //验证注册码 bool resu = RegInfo.CheckRegister(regCode+"1", ref time);
代码下载
链接:http://pan.baidu.com/s/1bpfFu3d 密码:lth3
阅读全文
0 0
- C#生成软件注册码
- C# 生成软件注册码
- C#生成注册码
- C#商业 软件 注册码 源码
- C#实现软件注册码算法
- C#给软件加注册码
- c#生成注册码 mac ip
- C#生成注册码及检验
- 软件注册码
- 软件注册码
- C#实现注册码 CPU序列号,生成机器码 生成注册码 判断是否注册
- 生成 注册码
- C# 注册码
- C# 给自己写的软件,加注册码功能
- C#实现无法破解的软件注册码算法
- C# 给自己写的软件,加注册码功能
- C#实现无法破解的软件注册码算法
- C#给自己的软件制作注册码(转)
- android反编译-修改别人apk(如何无视R文件,使用新增布局xml drawable等)
- Linux服务管理---系统运行级别、rpm启动与自启动、源码包的启动
- 常用Linux进程及作业管理命令
- 类的虚继承
- UESTC-1633 去年春恨却来时,落花人独立,微雨燕双飞(取模最短路)
- C# 生成软件注册码
- Error:SSL peer shut down incorrectly(完美解决)
- Redis 简解
- java-Collection(List、Set)
- 获取当前手机App版本以及AppStore中的最新版本,判断是否需要更新
- 在没有个人/公司网站的情况下,如何利用同一个二维码自动识别手机系统(Android/IOS)跳转不同下载页面
- IIS连接数据库:数据库连接出错,请检查连接字串
- 知识图谱相关介绍
- 以最大连续和为例的算法分析