C#程序怎么做注册码?

80酷酷网    80kuku.com

  程序

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using Hasher;
/// <summary>
/// cs 的摘要说明
/// </summary>
///
namespace cs
{
public class cs
{
//判断序列号
public bool css()
//m为配置文件值
//x为序列号值
//css进行比较该注册码是否正确
{
Hasher.Hasher hash = new Hasher.Hasher();
string xulie = hash.Sern();
string m = ConfigurationManager.AppSettings.Get("message").ToString();

if (m == xulie)
{
return true;

}
else
{
return false;

}

}

public bool text(string x)
//x为写入的参数
//用于注册码不正确的时候使用
{
Hasher.Hasher hash = new Hasher.Hasher();
string xulie = hash.Sern();
if (x == xulie)
{
return true;
}
else
{
return false;
}
}

public void con(string path, string x)
//写入配置文件信息
//path是请求的虚拟路径
//x要修改的值
{

Configuration config = WebConfigurationManager.OpenWebConfiguration(path);

config.AppSettings.Settings.Clear();
// string m = ConfigurationManager.AppSettings.Get("message");
config.AppSettings.Settings.Add("message", x);
config.Save();

}

}
}
 
 
Top
 
  回复人:wuda8(c# asp.net 2.0博客) ( ) 信誉:93 2006-11-1 15:37:43 得分:0
 
 
?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Security.Cryptography;
using System.Management;
/// <summary>
/// Hasher 的摘要说明
/// </summary>
///
namespace Hasher
{

public class Hasher
{

// private byte[] _HashKey; //哈希密钥存储变量
public string _HashText; //待加密的字符串
// public Hasher()
// {
// }

// 需要产生加密哈希的字符串
public string HashText
{
set
{
_HashText = value;
}
get
{
return _HashText;
}
}

/// 使用MD5CryptoServiceProvider类产生哈希值。不需要提供密钥。
/// </summary>
/// <returns></returns>
public string MD5Hasher()
{
byte[] MD5Data = System.Text.Encoding.UTF8.GetBytes(HashText);

MD5 Md5 = new MD5CryptoServiceProvider();

byte[] Result = Md5.ComputeHash(MD5Data);

return Convert.ToBase64String(Result); //返回长度为25字节字符串
}

//获取cpu序列号
public String GetCpuID()
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();

String strCpuID = null;
foreach (ManagementObject mo in moc)
{
strCpuID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strCpuID;
}//end method
//获取硬盘序列号
public String GetDriveID()
{
string driveSerialNum = "";
Scripting.FileSystemObjectClass MySystem = new Scripting.FileSystemObjectClass();
foreach (Scripting.Drive MyDriver in MySystem.Drives)
{
string SerialNumber = "";
try
{
SerialNumber = MyDriver.SerialNumber.ToString();
driveSerialNum = driveSerialNum + SerialNumber;
}
catch (Exception ex)
{

}

}

return driveSerialNum;
}

public String strJia()
{
string strJiami = "";
strJiami = GetCpuID() + GetDriveID();

return strJiami;
}
public string jiqixuelie;
public string duijiqima = null;
///得到机器码
public string hashGetDriveID()

{
Hasher hs = new Hasher();

hs.HashText = hs.strJia();
string jiqi = hs.MD5Hasher();
duijiqima = jiqi.Substring(8, 5);
return duijiqima;
}

public string Sern()
//最终的序列号 //m为配置文件值
//x为序列号值
//css进行比较该注册码是否正确
{

//888888888888888888888888888888888获取机器码
Hasher hs = new Hasher();

//88888888888888888888888888888888888888888888888888获取序列号
Hasher hash = new Hasher();
hash.HashText = hs.hashGetDriveID().ToString ();
jiqixuelie = hash.MD5Hasher();
return jiqixuelie;
}

}
 
 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: