如何限制调用方法
我想知道是否有办法限制对函数的invoke调用?让我说清楚。
[Assembly:a1]
Class A
{
function Af();
}
[Assembly:a2]
Class B
{
function Bf(){
//load Assembly a1
//InvokeMember to Af
}
}
编译后我将有 2 个程序集。现在,如果我分发给客户端,任何人都可以复制程序集 1 并调用 Af()。该函数在解密后返回setting.xml 文件。我想停止第三方访问我的函数。有什么办法吗?任何帮助表示赞赏。
谢谢。
I wonder if there is a way to restrict invoke call to a function? Let me make it clear.
[Assembly:a1]
Class A
{
function Af();
}
[Assembly:a2]
Class B
{
function Bf(){
//load Assembly a1
//InvokeMember to Af
}
}
After compilation I will have 2 assemblies. Now if I distribute to client, anyone can copy assembly 1 and invoke Af(). this function is returning setting.xml file after decrypting. I want to stop access to my function from third party. Is there any way? any help is appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在.NET中4.0 中,您可以使用 StrongNameIdentityPermission 来限制谁可以调用您的方法。但即便如此,也无法阻止有人决心获取您的秘密数据。
In .NET < 4.0, you could use the StrongNameIdentityPermission to restrict who's allowed to call your method. But even that will not stop someone who is determined to get hold of your secret data.
将 A 类嵌套在 B 类中。
Nest class A in Class B.
您可以通过要求传入一些参数才能使方法调用成功来混淆该方法。当前日期的 Base64Encode 或 MD5 可以工作(即使正确调用,也可能在 00:00:00 附近失败)。
他们仍然可以反思您的程序集并查看如何调用该方法。
恕我直言,你的担心是不必要的,但是一个好的混淆工具会有所帮助(我还没有在.Net 上尝试过这些,但我听说大多数都不好)。
You could obfuscate the method by requiring some argument be passed in for the method call to succeed. Base64Encode or MD5 of the current date could work (might fail near 00:00:00 even when called correctly though).
They could still reflect over your assembly and see how the method is called.
IMHO, your concern is unnecessary, but a good obfuscation tool would help (I haven't experimented with these much for .Net, but I've heard most are not good).