在研究程序的软件保护及解密,看到这个加密过程半天没搞懂。问一下各位高手,此程序的加密过程已知,然自己写的时候,要如何提供注册吗呢(也就是写注册机)?
程序的用户ID加密,自定义加密代码如下。
namespace Soft_Security
{
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Management;
using System.Web.Security;
[StandardModule]
internal sealed class Security
{
public static string _code;
public static string GetCode()
{
string expression = "";
ManagementClass class2 = new ManagementClass("Win32_PhysicalMedia");
foreach (ManagementObject obj2 in class2.GetInstances())
{
if (obj2.Properties["SerialNumber"].Value != null)
{
expression = obj2.Properties["SerialNumber"].Value.ToString();
}
if (Strings.Len(expression) > 1)
{
break;
}
}
if (Strings.Len(expression) == 0)
{
try
{
ManagementObject obj3 = new ManagementObject("Win32_LogicalDisk.DeviceID=\"C:\"");
expression = obj3.GetPropertyValue("VolumeSerialNumber").ToString();
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
Exception exception = exception1;
Interaction.MsgBox(exception.Message, MsgBoxStyle.ApplicationModal, null);
ProjectData.ClearProjectError();
}
}
if (Strings.Len(expression) == 0)
{
expression = "HD_ID_NOT_FOUND";
}
expression = FormsAuthentication.HashPasswordForStoringInConfigFile(expression, "SHA1").Substring(0, 0x20);
_code = expression;
return expression;
}
//验证过程
public static bool IsValid(string key)
{
_code = GetCode();
key = key.ToUpper().Replace("-", "");
if (Strings.Len(key) != 0x10)
{
return false;
}
string password = _code;
for (int i = 0; i < 0x4c; i++)
{
password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");
}
password = password.ToUpper();
while (password.Length < 0x10)
{
password = password + "ABC";
}
return password.StartsWith(key);
}
}
}
以上是程序加密函数。
注册界面自动生成一个用户字符串,生成的用户ID为获取上面Security的GetCode;
代码如下:this.jiami.Text = Security.GetCode();
点击注册按钮的代码如下:
Button1_Click 代码
try
{
if (Security.IsValid(Strings.Trim(this.TextBox2.Text)))
{
string name = @"Software\SoftKey";
RegistryKey key = Registry.LocalMachine.OpenSubKey(name, true);
if (key == null)
{
key = Registry.LocalMachine.CreateSubKey(name);
}
key.SetValue("Key", Strings.Trim(this.TextBox2.Text));
key.Close();
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show("请确认您输入了正确的注册码", "验证注册码失败");
}
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
Exception exception = exception1;
Interaction.MsgBox(exception.Message, MsgBoxStyle.ApplicationModal, null);
ProjectData.ClearProjectError();
}
这个的注册原理是什么?如何生成我的注册码呢?