Csharp/C#教程:如何使用C#加密另一个程序?分享


如何使用C#加密另一个程序?

因此,在Visual C#.NET中,我希望它能够以某种方式获取程序(通过打开的文件对话框),然后以某种方式获取该程序的字节并加密字节,以便稍后执行。

我该怎么办? 我如何使用Visual C#.NET加密,然后解密一个程序?

这个答案向您展示了如何执行字节数组。 一个警告,这可能会导致病毒扫描程序出现问题,因为它在恶意软件中很常见。

如果你不想从内存执行,我提出了一个如何加密存储然后解密并运行可执行文件的例子。

上述就是C#学习教程:如何使用C#加密另一个程序?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

public class FileEncryptRunner { Byte[] key = ASCIIEncoding.ASCII.GetBytes("thisisakeyzzzzzz"); Byte[] IV = ASCIIEncoding.ASCII.GetBytes("thisisadeltazzzz"); public void SaveEncryptedFile(string sourceFileName) { using (FileStream fStream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.Read), outFStream = new FileStream(Environment.SpecialFolder.MyDocuments+"test.crp", FileMode.Create)) { Rijndael RijndaelAlg = Rijndael.Create(); using (CryptoStream cStream = new CryptoStream(outFStream, RijndaelAlg.CreateEncryptor(key, IV), CryptoStreamMode.Write)) { StreamWriter sWriter = new StreamWriter(cStream); fStream.CopyTo(cStream); } } } public void ExecuteEncrypted() { using (FileStream fStream = new FileStream(Environment.SpecialFolder.MyDocuments + "test.crp", FileMode.Open, FileAccess.Read, FileShare.Read), outFStream = new FileStream(Environment.SpecialFolder.MyDocuments + "crpTemp.exe", FileMode.Create)) { Rijndael RijndaelAlg = Rijndael.Create(); using (CryptoStream cStream = new CryptoStream(fStream, RijndaelAlg.CreateDecryptor(key, IV), CryptoStreamMode.Read)) { //Here you have a choice. If you want it to only ever exist decrypted in memory then you have to use the method in // the linked answer. //If you want to run it from a file than it's easy and you save the file and run it, this is simple. cStream.CopyTo(outFStream); } } Process.Start(Environment.SpecialFolder.MyDocuments + "crpTemp.exe"); } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/957357.html

(0)
上一篇 2021年11月21日
下一篇 2021年11月21日

精彩推荐