Use encrypted assembly in C# application

I am trying to protect dlls I’m using in my WPF application from a simple copy. My solution is to encrypt the code section of these dlls and decrypt when it loads into my application.

There is a working way to do that using Assembly:

       using (FileStream fs = new FileStream(@"Mydll.dll", FileMode.Open, FileAccess.Read))
        {
            byte[] file = new byte[fs.Length];
            fs.Read(file, 0, (int) fs.Length);
            assemblyCashCode = Assembly.Load(file);
            Type[] types = assemblyCashCode.GetExportedTypes();

            Type t = MainWindow.assemblyCashCode.GetType("MyClass");
            MethodInfo[] mi = t.GetMethods();
            TypeInfo ti = t.GetTypeInfo();
            object cc = assemblyCashCode.CreateInstance("MyClass");
            int i = (int) t.InvokeMember("M3", BindingFlags.InvokeMethod, null, cc, null);
        }

But I will need to use the CreateInstance and InvokeMember methods every time I want to work with an object from this dll. It is a terrible perspective, isn’t it?

Is there another way to load these dlls instead of the CLR loader? Or just make the previous way easier?


Source: dll

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.