老歌新唱--使用VB6开发的ActiveX实现.NET程序的混淆加密
代码下载地址:
https://files.cnblogs.com/wuhuacong/VBActiveX.rar
由于存在一下几种特点:
1、.NET程序反编译容易,而使用一些混淆工具会导致有些程序不能运行
2、VB6开发ActiveX控件,那叫一个快,VB代码也不是很容易被反编译。
3、结合两者的特点,如果在.NET中使用了封装一些关键代码的ActiveX控件,那么程序的安全性是否好一点呢?
对于这种做法,请大家拍砖讨论,本人提供一个如何实现这种做法的思路。
一、 编写一个封装关键字符串或者实现逻辑的ActiveX控件
1、首先使用VB6创建一个ActiveX的工程项目
2、设置VB ActiveX的工程属性
3、编写类模块函数

Option
Explicit


Public
Function
GetString()
As
String

GetString
=
"
ABCDEFG
"

End Function



Public
Function
ValidateString(ByVal str
As
String
)
As
Boolean

ValidateString
=
False


If
str
=
"
ABCD
"
Then

ValidateString
=
True

Else

Err.Raise Err.Number, ,
"
不正确
"

End
If

End Function


Public
Function
GetDateTime()
As
Date


GetDateTime
=
Now


End Function
注意:如果使用Err.Raise函数,在调用过程中会抛出一个异常
二、在.NET程序中引用并使用该ActiveX控件
1、创建一个Windows Form程序
2、添加ActiveX控件的引用
3、编写按钮事件及ActiveX控件调用代码

using
System.Data;

using
System.Drawing;

using
System.Text;

using
System.Windows.Forms;


namespace
TestMyVBControl

{

public
partial
class
Form1 : Form

{

public
Form1()

{

InitializeComponent();

}


private
void
btnTest_Click(
object
sender, EventArgs e)

{

MyVBControl.TestClass test
=
new
MyVBControl.TestClass();

MessageBox.Show(test.GetString());

}


private
void
btnValidate_Click(
object
sender, EventArgs e)

{

MyVBControl.TestClass test
=
new
MyVBControl.TestClass();

try

{

MessageBox.Show(test.ValidateString(
"
ABCD
"
).ToString());
//
正确

MessageBox.Show(test.ValidateString(
"
ABCDE
"
).ToString());
//
有错误

}

catch
(Exception ex)

{

MessageBox.Show(ex.Message);

return
;

}

}


private
void
btnGetDate_Click(
object
sender, EventArgs e)

{

MyVBControl.TestClass test
=
new
MyVBControl.TestClass();

MessageBox.Show(test.GetDateTime().ToString());

}

}

}
结束,收工