为自己写的程序加一个注册功能吧。生成的机器号是根据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. JS结构图

  2. 自定义ViewPager控制是否滑动

    package com.lvshandian.menshen.view;/** * Created by zhang on 2016/11/8. * 创建自定义滑动,禁止滑动的ViewPager */ ...

  3. SGU 105 div.3 找规律

    There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. ...

  4. HDU 4442 Physical Examination

    Physical Examination Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  5. 安全漏洞API接口

    这个是avfisherapi写的API,经常用,每次找他的博客都搜到AV,尴尬..在这里记下来. 0x01 查询最新安全事件和漏洞的接口 接口URL: 乌云网: http://avfisherapi. ...

  6. 纯CSS写三角形-border法

    (1)有边框的三角形 我们来写下带边框的三角形. 如果是一个正方形,我们写边时,会用到border,但我们这里讨论的三角形本身就是border,不可能再给border添加border属性,所以我们需要 ...

  7. CUBRID学习笔记 14 dll加载错误

    这个问题通常是缺少文件cascci.dll 或者版本错误 32 64弄错了 C:\Program Files (x86)\Python266>python.exe Python 2.6.6 (r ...

  8. linux 查看是否安装perl模块

    这里介绍两种linux中查看perl模块是否安装的方法,一种是对于单体的模块,一种是对于群体的. 单体验证: [root@root ~]# perl -MShell -e "print\&q ...

  9. Spring管理bean的生命周期

    1: bean的创建:   如果我们默认的scope配置为Singleton的话, bean的创建实在Spring容器创建的时候创建: 如果scope的配置为Prototype的话,bena的创建是在 ...

  10. c 字符串常用函数

    #include <iostream> #include <stdio.h> #include <vector> #include "string.h&q ...