给软件增加注册功能 c#
1.软件注册类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
using System.IO;
using System.Diagnostics;
using System.Configuration; namespace Text2Excel.Helper
{
public static class SoftRegister
{
private static string SoftVersion = "V02";//v0.1
private static string SoftMD5 = string.Empty;
private static string DiskVolume = string.Empty;
private static string CPUSerialNum = string.Empty;
private static string PublicKey = "<RSAKeyValue><Modulus>kkrIPGLqt2CUSeSLC3l4lgJzLuBt0GGwTI7Jqt9SbHmj8Kaz5ffPbHY3aibx4jF8bmWlyNiO8LTc2qL6CV1mCL599mStYhIdePElE9+WxniSc3YCCzKxpTnWjRL7ROA25fQPJghAWUiWva7VamwjF0rLHDgX+rcuGF7LScY49B0=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
private static string getDiskVolume()
{
//ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
private static string getCPUserialNum()
{
string strCpu = null;
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuCollection = myCpu.GetInstances();
foreach (ManagementObject myObject in myCpuCollection)
{
strCpu = myObject.Properties["Processorid"].Value.ToString();
}
return strCpu;
}
private static string getSoftMD5()
{
string fileName = System.Windows.Forms.Application.ExecutablePath;
try
{
FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read);
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close(); StringBuilder sb = new StringBuilder();
for (int i = ; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString().ToUpper();
}
catch (Exception ex)
{
throw new Exception("GetMD5HashFromFile() fail,error:" + ex.Message);
}
}
public static void killMyself()
{
string bat = string.Format("@echo off \n ping -n 3 127.0.0.1 \n del {0}", System.Windows.Forms.Application.ExecutablePath);
File.WriteAllText("killme.bat", bat);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "killme.bat";
psi.Arguments = "\"" + Environment.GetCommandLineArgs()[] + "\"";
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
System.Environment.Exit();
//Application.Exit();
}
public static bool meIsMe(){
if (getSoftMD5().Substring(,) == SoftMD5)
{
return true;
}
else
{
return false;
}
}
public static string getMNum()
{
if (SoftMD5 == string.Empty)
{
SoftMD5 = getSoftMD5();
}
if (DiskVolume == string.Empty)
{
DiskVolume = getDiskVolume();
}
if (string.IsNullOrEmpty(CPUSerialNum))
{
CPUSerialNum = getCPUserialNum();
}
string strNum = SoftVersion + SoftMD5.Substring(, ) + CPUSerialNum.Substring(, ) + DiskVolume.Substring(, );
return strNum;//18个注册字符
}
public static bool toRegist(string cipher)
{
try
{
if (CryptionHelper.VerifySigned(getMNum(), cipher, PublicKey))
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
LogHelper.WriteLog(e);
return false;
} }
public static void updateConfig(string name, string value)
{
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
cfa.AppSettings.Settings[name].Value = value;
cfa.Save();
ConfigurationManager.RefreshSection("appSettings");
}
}
}
给软件增加注册功能 c#的更多相关文章
- python实现软件的注册功能(机器码+注册码机制)
http://www.cnblogs.com/cquptzzq/p/5940583.html 一.前言: 目的:完成已有python图像处理工具的注册功能 功能:用户运行程序后,通过文件自动检测认证状 ...
- Winform 注册机通用软件注册功能之建立有效的软件保护机制
本文转载:http://www.cnblogs.com/umplatform/archive/2013/01/23/2873001.html 众所周知,一些共享软件往往提供给使用者的是一个功能不受限制 ...
- C# 实现软件注册功能
相信很多初学编程的人都会对这个注册功能很感兴趣,我也不例外,刚学asp.net时,竞找不到这方面的实例,结果自己参考微软的一些文档自己做了一个,其实我做的这个注册功能很简单,读取计算机的CPU序列号, ...
- windows 增加右键功能 -->用命令行打开
windows 增加右键功能 -->用命令行打开 实现 注册表 以管理员权限CMD 到指定文件夹 Windows Registry Editor Version 5.00 [HKEY_CLASS ...
- C# 给软件加注册码功能
为自己写的程序加一个注册功能吧.生成的机器号是根据CPU和硬盘号来的,根据自己的需求改成是否是随机生成. 代码直接粘贴到新建类覆盖原代码就能直接用了. using System; using Syst ...
- apktool给软件加注册机修改图标和文件名
功能实现,即让你的软件具有注册机功能,或者破解别人的软件,据为己有! 先反编译文件包 然后全局工具,修改图标和名称 加注册机,输入key,下载计算器,即可.给某个用户设置自定义的使用时间!
- Java Spring+Mysql+Mybatis 实现用户登录注册功能
前言: 最近在学习Java的编程,前辈让我写一个包含数据库和前端的用户登录功能,通过看博客等我先是写了一个最基础的servlet+jsp,再到后来开始用maven进行编程,最终的完成版是一个 Spri ...
- BBS-基于forms组件和ajax实现注册功能
http://www.cnblogs.com/yuanchenqi/articles/7638956.html 1.设计注册页面 views.py from django import forms c ...
- 使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(五)——实现注册功能
使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(一)——创建应用 使用 Flask 框架写用户登录功能的Demo时碰到的各种坑(二)——使用蓝图功能进行模块化 使用 Flask 框架写用 ...
随机推荐
- How can I save HICON to an .ico file
refer:http://stackoverflow.com/questions/2289894/how-can-i-save-hicon-to-an-ico-file answer1: #inclu ...
- Centos6.5使用yum安装Mysql5.7
想要玩新的东东就要付出代价,我的时间悄悄的都溜走了,说多了都是泪! 实践才是真理! 系统版本:Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 ...
- php 之 数据访问 查询关键字 (0506)
根据数据库中的car表做一个汽车查询页面: 一.一个关键字查询: 主页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transiti ...
- ubuntu soft install
1.Mysql 安装就三个命令 mysql服务端 sudo apt-get install mysql-server mysql客户端 sudo apt-get install mysql-clien ...
- Android ndk第一步,构建jni headers
转载请注明出处:http://www.cnblogs.com/fpzeng/p/4281801.html 源码请见 https://github.com/fpzeng/HelloJNI PC系统: u ...
- JNI学习&使用过程中的错误
Part 1 Ubuntu下JNI的简单使用: http://blog.csdn.net/fengqiaoyebo2008/article/details/6210499 Part 2 在eclips ...
- Swift--存储属性-备
Swift中的属性分为存储属性和计算属性,存储属性就是Objective-C中的数据成员,计算属性不存储数据,但可以通过计算其他属性返回数据. 存储属性可以存储数据,分为常量属性(用关键字let定义) ...
- Effective Java实作Comparator - 就是爱Java
如果集合或数组内的对象,有1个以上不同的排序逻辑时,那该如何处理呢?尤其是当已经实现了Comparable,又不能变动原本的逻辑时,Mix会采用Comparator来处理. 阅读全文>>
- SMTP协议--在cmd下利用命令行发送邮件
先简单介绍下smtp smtp使用命令和应答在客户与服务器之间传输报文.即客户发出一个命令,服务器返回一个应答.发送方与接收方进行一问一答的交互,由发送方控制这个对话. 在XP系统下点‘开始’-‘运行 ...
- cf B. Levko and Permutation
http://codeforces.com/contest/361/problem/B #include <cstdio> #include <cstring> #includ ...