Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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_Stub - Fatal编程技术网

C# 如何用存根包装我的生成器?

C# 如何用存根包装我的生成器?,c#,.net,encryption,stub,C#,.net,Encryption,Stub,我目前正在学习密码器,这是我到目前为止所学到的 密码器由生成器和存根组成 构建器角色是加密文件,存根包装文件 并使其在被解密的机器内存中的缓冲区中运行。 (如果我错了,请改正) 我已经创建了我的文件加密程序(生成器),老实说,我不知道如何创建存根。。我已经找了一整天了,但我能找到的只是这些非常旧的控制台应用程序,它们并没有真正解释任何东西 所以我的问题是.. 如何用存根包装当前的文件加密程序。。或者如何创建存根。我不知道该如何回答这个问题,因为我对存根还不熟悉 这是我的文件加密机 using S

我目前正在学习密码器,这是我到目前为止所学到的

密码器由生成器和存根组成

构建器角色是加密文件,存根包装文件 并使其在被解密的机器内存中的缓冲区中运行。 (如果我错了,请改正)

我已经创建了我的文件加密程序(生成器),老实说,我不知道如何创建存根。。我已经找了一整天了,但我能找到的只是这些非常旧的控制台应用程序,它们并没有真正解释任何东西

所以我的问题是.. 如何用存根包装当前的文件加密程序。。或者如何创建存根。我不知道该如何回答这个问题,因为我对存根还不熟悉

这是我的文件加密机

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows;
using Microsoft.Win32;
using System.Security.Cryptography;
using System.IO;

namespace FileEncrypter
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        string key;
        public MainWindow()
        {
            InitializeComponent();
            key = generateKey();
        }

        public string generateKey()
        {
            DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();
            return ASCIIEncoding.ASCII.GetString(desCrypto.Key);
        }

        private void EncryptBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.ShowDialog();

                inputencryptFileTextBox.Text = ofd.FileName;

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.ShowDialog();

                outputencryptFileTextBox.Text = sfd.FileName;

                encrypt(inputencryptFileTextBox.Text, outputencryptFileTextBox.Text, key);
                MessageBox.Show("File has been encrypted.", "File");

            }
            catch(Exception encEx)
            {
                MessageBox.Show(encEx.ToString());
            }

        }

        private void encrypt(string input, string output, string strhash)
        {
            FileStream inFs, outFs;
            CryptoStream cs;
            TripleDESCryptoServiceProvider TDC = new TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] byteHash, byteTexto;

            inFs = new FileStream(input, FileMode.Open, FileAccess.Read);
            outFs = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write);

            byteHash = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strhash));
            byteTexto = File.ReadAllBytes(input);

            md5.Clear();

            TDC.Key = byteHash;
            TDC.Mode = CipherMode.ECB;

            cs = new CryptoStream(outFs, TDC.CreateEncryptor(), CryptoStreamMode.Write);

            int byteRead;
            long length, position = 0;
            length = inFs.Length;

            while (position < length)
            {
                byteRead = inFs.Read(byteTexto, 0, byteTexto.Length);
                position += byteRead;

                cs.Write(byteTexto, 0, byteRead);

            }

            inFs.Close();
            outFs.Close();

        }

        private void DecryptBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.ShowDialog();

                inputdecryptFileTextBox.Text = ofd.FileName;

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.ShowDialog();

                outputdecryptFileTextBox.Text = sfd.FileName;

                decrypt(inputdecryptFileTextBox.Text, outputdecryptFileTextBox.Text, key);
                MessageBox.Show("File has been decrypted.", "File");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }



        private void decrypt(string input, string output, string strhash)
        {
            FileStream inFs, outFs;
            CryptoStream cs;
            TripleDESCryptoServiceProvider TDC = new TripleDESCryptoServiceProvider();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] byteHash, byteTexto;

            inFs = new FileStream(input, FileMode.Open, FileAccess.Read);
            outFs = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write);

            byteHash = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strhash));
            byteTexto = File.ReadAllBytes(input);

            md5.Clear();

            TDC.Key = byteHash;
            TDC.Mode = CipherMode.ECB;

            cs = new CryptoStream(outFs, TDC.CreateDecryptor(), CryptoStreamMode.Write);

            int byteRead;
            long length, position = 0;
            length = inFs.Length;

            while (position < length)
            {
                byteRead = inFs.Read(byteTexto, 0, byteTexto.Length);
                position += byteRead;

                cs.Write(byteTexto, 0, byteRead);

            }

            inFs.Close();
            outFs.Close();

        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用System.Windows;
使用Microsoft.Win32;
使用System.Security.Cryptography;
使用System.IO;
命名空间文件加密程序
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
字符串键;
公共主窗口()
{
初始化组件();
key=generateKey();
}
公共字符串generateKey()
{
DESCryptoServiceProvider desCrypto=(DESCryptoServiceProvider)DESCryptoServiceProvider.Create();
返回ascienceoding.ASCII.GetString(desCrypto.Key);
}
私有void EncryptBtn_单击(对象发送方,路由目标)
{
尝试
{
OpenFileDialog ofd=新建OpenFileDialog();
ShowDialog();
inputencryptFileTextBox.Text=ofd.FileName;
SaveFileDialog sfd=新建SaveFileDialog();
ShowDialog();
outputencryptFileTextBox.Text=sfd.FileName;
加密(inputencryptFileTextBox.Text,outputencryptFileTextBox.Text,密钥);
Show(“文件已加密。”,“文件”);
}
捕获(异常encEx)
{
Show(encEx.ToString());
}
}
私有void加密(字符串输入、字符串输出、字符串strhash)
{
文件流输入、输出;
密码流;
TripleDESCryptoServiceProvider TDC=新的TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5=新的MD5CryptoServiceProvider();
字节[]字节哈希,字节扩展;
inFs=新文件流(输入,FileMode.Open,FileAccess.Read);
outps=新文件流(输出,FileMode.OpenOrCreate,FileAccess.Write);
byteHash=md5.ComputeHash(ascienceoding.ASCII.GetBytes(strhash));
byteTexto=File.ReadAllBytes(输入);
md5.Clear();
密钥=字节哈希;
TDC.Mode=CipherMode.ECB;
cs=新的加密流(outps,TDC.CreateEncryptor(),CryptoStreamMode.Write);
内特比德;
长长度,位置=0;
长度=输入长度;
while(位置<长度)
{
byteRead=inFs.Read(byteTexto,0,byteTexto.Length);
位置+=byteRead;
cs.Write(byteTexto,0,byteRead);
}
inFs.Close();
outps.Close();
}
私有void DecryptBtn_单击(对象发送方,路由目标)
{
尝试
{
OpenFileDialog ofd=新建OpenFileDialog();
ShowDialog();
inputdecryptFileTextBox.Text=ofd.FileName;
SaveFileDialog sfd=新建SaveFileDialog();
ShowDialog();
outputdecryptFileTextBox.Text=sfd.FileName;
解密(inputdecryptFileTextBox.Text,outputdecryptFileTextBox.Text,密钥);
Show(“文件已被解密。”,“文件”);
}
捕获(例外情况除外)
{
Show(例如ToString());
}
}
私有void解密(字符串输入、字符串输出、字符串strhash)
{
文件流输入、输出;
密码流;
TripleDESCryptoServiceProvider TDC=新的TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider md5=新的MD5CryptoServiceProvider();
字节[]字节哈希,字节扩展;
inFs=新文件流(输入,FileMode.Open,FileAccess.Read);
outps=新文件流(输出,FileMode.OpenOrCreate,FileAccess.Write);
byteHash=md5.ComputeHash(ascienceoding.ASCII.GetBytes(strhash));
byteTexto=File.ReadAllBytes(输入);
md5.Clear();
密钥=字节哈希;
TDC.Mode=CipherMode.ECB;
cs=新的加密流(outps,TDC.createdecryptogrator(),CryptoStreamMode.Write);
内特比德;
长长度,位置=0;
长度=输入长度;
while(位置<长度)
{
byteRead=inFs.Read(byteTexto,0,byteTexto.Length);
位置+=byteRead;
cs.Write(byteTexto,0,byteRead);
}
inFs.Close();
outps.Close();
}
}
}

存根可以是一个小项目,加密部分作为资源。加载存根时,它将从资源中取消程序集的脚本,并使用反射来查找“主入口点”。问题是,如何保留私钥。。。。UH私有..

存根可以是一个小项目