Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#应用程序中使用加密程序集_C#_.net_Encryption_Dll_Clr - Fatal编程技术网

在C#应用程序中使用加密程序集

在C#应用程序中使用加密程序集,c#,.net,encryption,dll,clr,C#,.net,Encryption,Dll,Clr,我试图保护我在WPF应用程序中使用的DLL不受简单副本的影响。我的解决方案是加密这些DLL的代码部分,并在加载到应用程序时解密 使用Assembly有一种工作方式: using (FileStream fs = new FileStream(@"Mydll.dll", FileMode.Open, FileAccess.Read)) { byte[] file = new byte[fs.Length]; fs.Rea

我试图保护我在WPF应用程序中使用的DLL不受简单副本的影响。我的解决方案是加密这些DLL的代码部分,并在加载到应用程序时解密

使用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);
        }
但是每当我想处理这个dll中的对象时,我都需要使用CreateInstance和InvokeMember方法。这是一个可怕的观点,不是吗

是否有其他方法来加载这些DLL而不是CLR加载程序?或者只是让前面的方法更简单?

是的,实施该事件


当程序集解析失败时会触发此事件(您需要将程序集存储在程序集解析找不到它们的地方),然后在加载和解密程序集后,您可以说“哦,它在这里”。

AppDomain.AssemblyResolve是执行此类操作的地方,但请注意,这可能不会起到多大的保护作用。您可以在WinDBG中运行应用程序,然后执行以下操作。我不是百分之百确定,但这将保存内存中的未加密版本。