Ejemplo n.º 1
0
        private void Button_EncryAssembly_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tb_AssemblyPath.Text) || string.IsNullOrEmpty(tb_encryKey.Text))
            {
                return;
            }

            EncryKey = tb_encryKey.Text;
            ThreadPool.QueueUserWorkItem(new WaitCallback((obj) =>
            {
                try
                {
                    byte[] assemblyByteData = File.ReadAllBytes(openFilePath);
                    byte[] encryBytes       = ByteEncry.EncryptionToBytes(assemblyByteData, EncryKey);
                    string dirPath          = Path.GetDirectoryName(openFilePath);
                    File.WriteAllBytes(Path.Combine(dirPath, "加密后的程序集.dll"), encryBytes);

                    MessageBox.Show("加密成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }));
        }
Ejemplo n.º 2
0
        private void Button_UnEncryAssembly_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tb_UnEncryKey.Text))
            {
                return;
            }

            UnEncryKey = tb_UnEncryKey.Text;
            ThreadPool.QueueUserWorkItem(new WaitCallback((obj) =>
            {
                try
                {
                    byte[] hadEncryBytes    = File.ReadAllBytes(openFilePath);
                    byte[] assemblyByteData = ByteEncry.UnEncryptionToBytes(hadEncryBytes, UnEncryKey);

                    string dirPath = Path.GetDirectoryName(openFilePath);
                    File.WriteAllBytes(Path.Combine(dirPath, "解密后的程序集.dll"), assemblyByteData);

                    asm          = Assembly.Load(assemblyByteData);
                    Type[] types = asm.GetTypes();

                    this.Dispatcher.BeginInvoke(new ThreadStart(() =>
                    {
                        TypeList.Items.Clear();
                        foreach (var type in types)
                        {
                            TypeList.Items.Add(type.FullName);
                        }
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }));
        }