为自己写的程序加一个注册功能吧。生成的机器号是根据CPU和硬盘号来的,根据自己的需求改成是否是随机生成。

  代码直接粘贴到新建类覆盖原代码就能直接用了。

using System;
using System.Management;
using System.Security.Cryptography;
using System.Text; namespace RegisterClass
{
class RegisterClass
{
//步骤一: 获得CUP序列号和硬盘序列号的实现代码如下:
//获得CPU的序列号 bool Stupids = true;
bool Cat = false;
public string getCpu()
{
string strCpu = null;
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
foreach( ManagementObject myObject in myCpuConnection)
{
strCpu = myObject.Properties["Processorid"].Value.ToString();
break;
}
return strCpu;
} //取得设备硬盘的卷标号 public string GetDiskVolumeSerialNumber()
{
ManagementClass mc =
new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObject disk =
new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
} //步骤二: 收集硬件信息生成机器码, 代码如下:
//生成机器码 public string CreateCode()
{
string temp = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号
string[] strid = new string[];//
for (int i = ; i < ; i++)//把字符赋给数组
{
strid[i] = temp.Substring(i, );
}
temp = "";
//Random rdid = new Random();
for (int i = ; i < ; i++)//从数组随机抽取24个字符组成新的字符生成机器三
{
//temp += strid[rdid.Next(0, 24)];
temp += strid[i+>=?:i+];
}
return GetMd5(temp);
} //步骤三: 使用机器码生成软件注册码, 代码如下:
//使用机器码生成注册码
public int[] intCode = new int[];//用于存密钥 public void setIntCode()//给数组赋值个小于10的随机数
{
//Random ra = new Random();
//for (int i = 1; i < intCode.Length;i++ )
//{
// intCode[i] = ra.Next(0, 9);
//}
for (int i = ; i < intCode.Length; i++)
{
intCode[i] = i + > ? : i + ;
}
}
public int[] intNumber = new int[];//用于存机器码的Ascii值
public char[] Charcode = new char[];//存储机器码字 //生成注册码
public string GetCode(string code)
{
if (code != "")
{
//把机器码存入数组中
setIntCode();//初始化127位数组
for (int i = ; i < Charcode.Length; i++)//把机器码存入数组中
{
Charcode[i] = Convert.ToChar(code.Substring(i - , ));
}//
for (int j = ; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。
{
intNumber[j] =
intCode[Convert.ToInt32(Charcode[j])] +
Convert.ToInt32(Charcode[j]); }
string strAsciiName = null;//用于存储机器码
for (int j = ; j < intNumber.Length; j++)
{
//MessageBox.Show((Convert.ToChar(intNumber[j])).ToString());
//判断字符ASCII值是否0-9之间 if (intNumber[j] >= && intNumber[j] <= )
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
//判断字符ASCII值是否A-Z之间 else if (intNumber[j] >= && intNumber[j] <= )
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
//判断字符ASCII值是否a-z之间 else if (intNumber[j] >= && intNumber[j] <= )
{
strAsciiName += Convert.ToChar(intNumber[j]).ToString();
}
else//判断字符ASCII值不在以上范围内
{
if (intNumber[j] > )//判断字符ASCII值是否大于z
{
strAsciiName += Convert.ToChar(intNumber[j] - ).ToString();
}
else
{
strAsciiName += Convert.ToChar(intNumber[j] - ).ToString();
} }
//label3.Text = strAsciiName;//得到注册码
}
return strAsciiName;
}
else
{
return "";
}
} //步骤四: 用户输入注册码注册软件, 演示代码如下: //注册
public bool RegistIt(string currentCode,string realCode)
{
if (realCode != "")
{
if (currentCode.TrimEnd().Equals(realCode.TrimEnd()))
{
Microsoft.Win32.RegistryKey retkey =
Microsoft.Win32.Registry.CurrentUser.
OpenSubKey("software", true).CreateSubKey("StupidsCat").
CreateSubKey("StupidsCat.ini").
CreateSubKey(currentCode.TrimEnd());
retkey.SetValue("StupidsCat", "BBC6D58D0953F027760A046D58D52786"); retkey = Microsoft.Win32.Registry.LocalMachine.
OpenSubKey("software", true).CreateSubKey("StupidsCat").
CreateSubKey("StupidsCat.ini").
CreateSubKey(currentCode.TrimEnd());
retkey.SetValue("StupidsCat", "BBC6D58D0953F027760A046D58D52786"); return Stupids;
}
else
{
return Cat;
}
}
else { return Cat; }
} public bool BoolRegist(string sn)
{
string[] keynames; bool flag = false;
Microsoft.Win32.RegistryKey localRegKey = Microsoft.Win32.Registry.LocalMachine;
Microsoft.Win32.RegistryKey userRegKey = Microsoft.Win32.Registry.CurrentUser;
try
{
keynames = localRegKey.OpenSubKey("software\\StupidsCat\\StupidsCat.ini\\" + GetMd5(sn)).GetValueNames();
foreach (string name in keynames)
{
if (name == "StupidsCat")
{
if (localRegKey.OpenSubKey("software\\StupidsCat\\StupidsCat.ini\\" + GetMd5(sn)).GetValue("StupidsCat").ToString() == "BBC6D58D0953F027760A046D58D52786")
flag = true;
}
}
keynames = userRegKey.OpenSubKey("software\\StupidsCat\\StupidsCat.ini\\" + GetMd5(sn)).GetValueNames();
foreach (string name in keynames)
{
if (name == "StupidsCat")
{
if (flag && userRegKey.OpenSubKey("software\\StupidsCat\\StupidsCat.ini\\" + GetMd5(sn)).GetValue("StupidsCat").ToString() == "BBC6D58D0953F027760A046D58D52786")
return true;
}
}
return false;
}
catch
{
return false;
}
finally
{
localRegKey.Close();
userRegKey.Close();
}
} public string GetMd5(object text)
{
string path = text.ToString(); MD5CryptoServiceProvider MD5Pro = new MD5CryptoServiceProvider();
Byte[] buffer = Encoding.GetEncoding("utf-8").GetBytes(text.ToString());
Byte[] byteResult = MD5Pro.ComputeHash(buffer); string md5result = BitConverter.ToString(byteResult).Replace("-", "");
return md5result;
}
}
}

C# 给软件加注册码功能的更多相关文章

  1. C# winform利用反射和自定义特性加载功能模块(插件式开发)

    由于在实际的工作中, 碰见这样的一个问题: 一个软件, 销售给A客户 他需要所有功能, 但是销售给B客户, 他只需要其中的一部分, 1.如果我们在实际的开发过程中, 没有把一些功能模块区分开来的话, ...

  2. 利用破解dll来获取到一个软件的注册码

    ---恢复内容开始--- 首先做这个事是纯属于个人研究而已,请勿以侵犯他人劳动成果. 今天看到了一个关于IL语句的文章,于是就学学,然后实践实践下.废话不多说了. 1.安装好某一个需要注册才可以的使用 ...

  3. IOS UITableView下拉刷新和上拉加载功能的实现

    在IOS开发中UITableView是非常常用的一个功能,而在使用UITableView的时候我们经常要用到下拉刷新和上拉加载的功能,今天花时间实现了简单的UITableView的下拉刷新和上拉加载功 ...

  4. Kooboo 加Search功能 必须先ReBuild Index Data

      加Search功能   有几个要点 1. 需要在Kooboo 必须先 ReBuild Index Data 2. 需要在要搜索的page中启用搜索索引         搜索的代码 @using K ...

  5. 微信消息体签名及加解密功能详细解析以及.net实现

    原文:微信消息体签名及加解密功能详细解析以及.net实现 前言 微信消息体签名及加密功能已上线,明文传输确实存在安全风险,鉴于微信的用户范围使用之广泛,必定会成为众矢之的.所以大家还是尽快接入安全模式 ...

  6. asp.net mvc上传头像加剪裁功能

    原文:asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jqu ...

  7. mvc上传头像加剪裁功能

    asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jquery ...

  8. 用Go自己实现配置文件热加载功能

    说到配置文件热加载,这个功能在很多框架中都提供了,如beego,实现的效果就是当你修改文件后,会把你修改后的配置重新加载到配置文件中,而不用重启程序,这个功能在日常中还是非常实用的,毕竟很多时候,线上 ...

  9. RecyclerViewLoadMoreDemo【封装上拉加载功能的RecyclerView,搭配SwipeRefreshLayout实现下拉刷新】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 封装含有上拉加载功能的RecyclerView,然后搭配SwipeRefreshLayout实现下拉刷新.上拉加载功能. 在项目中将 ...

随机推荐

  1. Java中Properties类的操作配置文件

    知识学而不用,就等于没用,到真正用到的时 候还得重新再学.最近在看几款开源模拟器的源码,里面涉及到了很多关于Properties类的引用,由于Java已经好久没用了,而这些模拟器大多用 Java来写, ...

  2. 在centos6.3用yum安装redis

    一.centos默认的安装源在官方centos.org上,而redis在第三方的yum源里,所以无法安装,非官方的yum推荐用fedora的epel仓库.当然也可通过配置 /etc/yum.repos ...

  3. SignalR记录

    服务端检索数据库,有跟新,推送给客户端 1: GlobalHost.ConnectionManager.GetHubContext<tvHub>().Clients.Client(Clie ...

  4. jquery之 off()方法

    off()函数用于移除元素上绑定的一个或多个事件的事件处理函数. off()函数主要用于解除由on()函数绑定的事件处理函数. 该函数属于jQuery对象(实例). 语法 jQuery 1.7 新增该 ...

  5. 取消mod_sofia的呼叫鉴权

    FreeSWITCH中默认的SIP呼叫是要鉴权的,流程如下. 终端 FreeSWITCH A -----Invite------> FS A <----Trying------ FS A ...

  6. C#中Monitor和Lock以及区别

    Monitor对象 1.Monitor.Enter(object)方法是获取锁,Monitor.Exit(object)方法是释放锁,这就是Monitor最常用的两个方法,当然在使用过程中为了避免获取 ...

  7. JAVA 大数据内存耗用测试

    JAVA 大数据内存耗用测试import java.lang.management.ManagementFactory;import java.lang.management.MemoryMXBean ...

  8. SQL触发器、事务

    触发器: 触发器为特殊类型的存储过程,可在执行语言事件时自动生效.SQL Server 包括三种常规类型的触发器:DML 触发器.DDL 触发器和登录触发器. 当服务器或数据库中发生数据定义语言 (D ...

  9. spring之aop概念和配置

    面向切面的一些概念: 简单说: 连接点就一些方法,在这些方法基础上需要额外的一些业务需求处理. 切入点就是方法所代表的功能点组合起来的功能需求. 通知就是那些额外的操作. 织入就是使用代理实现整个切入 ...

  10. [转载] 深入 nginx 架构

    原文: http://www.cnbeta.com/articles/402709.htm 了解 nginx 架构帮助我们学习如何开发高性能 web 服务. 为了更好地理解设计,你需要了解NGINX是 ...