我想要对自己的软件进行加密,
让用户使用时要输入注册码我们经常用的软件在包装上都有序列号
让用户使用时要输入注册码我们经常用的软件在包装上都有序列号
解决方案 »
- 关于C#读取Excel表中sheet1为任意名字的问题
- c#调用VC6的DLL文件。DLL函数参数有结构体,有MFC调用dll代码。不知道如何处理了
- 请各位大侠帮我解释一下:SocketAsyncEventArgsPool
- 看似简单!解读C#程序员最易犯的7大错误
- .net怎么将大图缩小小图?
- 请教,关于验证控件RequiredFieldValidator
- (求助)请问哪一个工具可以查看如system32.dll,netapi32.dll,api32.dll里面提供哪些方法?
- ???
- 在WinFrom中如何遍历DataGrid控件中的每个数据项
- PDA中如何检测网络是否可用
- [求助]ADO.Net:删除多行时产生并发错误。
- 有谁能解决让winform的datagrid响应row的单击事件和双击事件
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;namespace test
{
/// <summary>
/// GetSystemVol 的摘要说明。
/// </summary>
public class GetSystemVol
{
public GetSystemVol()
{
} #region 加密 [DllImport("kernel32.dll")]
private static extern int GetVolumeInformation(
string lpRootPathName,
string lpVolumeNameBuffer,
int nVolumeNameSize,
ref int lpVolumeSerialNumber,
int lpMaximumComponentLength,
int lpFileSystemFlags,
string lpFileSystemNameBuffer,
int nFileSystemNameSize
);
/// <summary>
/// 获取指定盘符的硬盘串号
/// </summary>
/// <param name="drvID">盘符</param>
/// <returns></returns>
public static string GetVolOf(string drvID)
{
if(drvID.Length >1)
{
drvID = "C";
}
const int MAX_FILENAME_LEN = 256;
int retVal = 0;
int a =0;
int b =0;
string str1 = null;
string str2 = null; int i = GetVolumeInformation(
drvID + @":\",
str1,
MAX_FILENAME_LEN,
ref retVal,
a,
b,
str2,
MAX_FILENAME_LEN
);
return retVal.ToString("x");
} /// <summary>
/// 获取字符串的MD5加密算法
/// </summary>
/// <param name="sDataIn"></param>
/// <returns></returns>
public static string GetMD5(string sDataIn)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5=new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[]bytValue,bytHash;
bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
bytHash = md5.ComputeHash(bytValue);
md5.Clear();
string sTemp="";
for(int i=0;i<bytHash.Length;i++)
{
sTemp+=bytHash[i].ToString("X").PadLeft(2,'0');
}
return sTemp.ToUpper();
} #endregion #region 注册表操作 /// <summary>
/// 读取指定名称的注册表的值
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string GetRegistData(string name)
{
string registData;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE",true);
RegistryKey aimdir = software.OpenSubKey("henanljw",true);
registData = aimdir.GetValue(name).ToString();
return registData;
}
/// <summary>
/// 向注册表中写数据
/// </summary>
/// <param name="name">注册表串值</param>
/// <param name="tovalue">要写的数据值</param>
/// <returns>写入成功返回true,否则返回false</returns>
public static bool WTRegedit(string name,string tovalue)
{
try
{
RegistryKey hklm = Registry.LocalMachine;
RegistryKey software = hklm.OpenSubKey("SOFTWARE",true);
RegistryKey aimdir = software.CreateSubKey("henanljw");
aimdir.SetValue(name,tovalue);
return true;
}
catch
{
return false;
}
} /// <summary>
/// 删除注册表中指定的注册表项
/// </summary>
/// <param name="name"></param>
public static void DeleteRegist(string name)
{
string[] aimnames;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE",true);
// RegistryKey aimdir = software.OpenSubKey("henanljw",true);
// aimnames = aimdir.GetSubKeyNames();
aimnames = software.GetSubKeyNames();
foreach(string aimKey in aimnames)
{
if(aimKey == name)
software.DeleteSubKeyTree(name);
}
}
/// <summary>
/// 判断指定注册表项是否存在
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static bool IsRegeditExit(string name)
{
bool _exit = false;
string[] subkeyNames;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE",true);
// RegistryKey aimdir = software.OpenSubKey("henanljw",true);
subkeyNames = software.GetSubKeyNames();
// subkeyNames = aimdir.GetValueNames();
foreach(string keyName in subkeyNames)
{
if(keyName == name)
{
_exit = true;
return _exit;
}
}
return _exit;
} #endregion
}
}