一个软件的诞生都会牵涉到版权控制,但不管加密如何复杂即使像微软的东西也依然能予以破解,只是时间问题.版本的控制犹如保险柜上锁,仅仅防君子而已.那么软件是如何控制版本的呢,基本上无非就是在程序中添加了一段经过自己编写算法(这个算法可以是简单的公式运算,也可以是复杂的结合硬件的绑定方式),将形成的序列号注册到我们的注册表中.每当程序运行的时候都去读取注册表信息并验证一把.
下面是一个简单的License生成器代码
代码
public partial class LicenseCreator : Form
{
public LicenseCreator()
{
InitializeComponent();
}
private void btnLincenseCreator_Click(object sender, EventArgs e)
{
string licenseKey = GetLicenseKey(txtUsername.Text);
txtLincense.Text = licenseKey;
}
//通过自定义算法返回序列号
private string GetLicenseKey(string username)
{
int breakCount = 8;
//定制算法可根据个人修改
username =
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(
Math.Abs(~System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(username, "md5").GetHashCode() ^ 0x2010 << 3)
.ToString(), "sha1");
StringBuilder result = new StringBuilder();
for (int i = 0; i < username.Length; i++)
{
result.Append(username.Substring(i, 1));
if ((i + 1) % breakCount == 0)
{
result.Append("-");
}
}
return result.ToString().TrimEnd('-');
}
//注册信息
private void btnRegedit_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtLincense.Text))
{
MessageBox.Show("请生成Lincese后重新注册");
return;
}
string regeditKey = @"Licenses\DFF31A6A-A5C2-48A7-B4D9-3C1151676FC8\";
RegistryKey classesRootKey = Registry.ClassesRoot;
RegistryKey licenseKey = classesRootKey.CreateSubKey(regeditKey);
licenseKey.SetValue("UserName", txtUsername.Text);
licenseKey.SetValue("Key", txtLincense.Text);
MessageBox.Show("注册成功!");
}
private void btnClear_Click(object sender, EventArgs e)
{
txtUsername.Text = string.Empty;
txtLincense.Text = string.Empty;
txtUsername.Focus();
}
{
public LicenseCreator()
{
InitializeComponent();
}
private void btnLincenseCreator_Click(object sender, EventArgs e)
{
string licenseKey = GetLicenseKey(txtUsername.Text);
txtLincense.Text = licenseKey;
}
//通过自定义算法返回序列号
private string GetLicenseKey(string username)
{
int breakCount = 8;
//定制算法可根据个人修改
username =
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(
Math.Abs(~System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(username, "md5").GetHashCode() ^ 0x2010 << 3)
.ToString(), "sha1");
StringBuilder result = new StringBuilder();
for (int i = 0; i < username.Length; i++)
{
result.Append(username.Substring(i, 1));
if ((i + 1) % breakCount == 0)
{
result.Append("-");
}
}
return result.ToString().TrimEnd('-');
}
//注册信息
private void btnRegedit_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtLincense.Text))
{
MessageBox.Show("请生成Lincese后重新注册");
return;
}
string regeditKey = @"Licenses\DFF31A6A-A5C2-48A7-B4D9-3C1151676FC8\";
RegistryKey classesRootKey = Registry.ClassesRoot;
RegistryKey licenseKey = classesRootKey.CreateSubKey(regeditKey);
licenseKey.SetValue("UserName", txtUsername.Text);
licenseKey.SetValue("Key", txtLincense.Text);
MessageBox.Show("注册成功!");
}
private void btnClear_Click(object sender, EventArgs e)
{
txtUsername.Text = string.Empty;
txtLincense.Text = string.Empty;
txtUsername.Focus();
}