views:

34

answers:

3

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.

A: 

Nest class A in Class B.

sarahTheButterFly
Hi.. I guess you got me wrong.. my doubt is here. Output of my project will be say a1.exe and a2.dll. Now any of my client will copy a1.exe and put in his new project release folder and write a code to InvokeMember("Af") then he will be able to get output of decrypted xml. I want to protect it. Is there any way?
Akie
+2  A: 

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.

Mattias S
A: 

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).

marr75