0

I've created a program to receive a hash code of an .exe file. And than with streamwriter I wrote it to an .exe file. If I wanna open the .exe of it I get the error: is not a valid win32 application.

What can I do with the hash and is it possible to create an .exe file from it that works.

Thank you very much!

byte[] hash;
using (Stream stream = File.OpenRead(@"C:\Program files\CCleaner\CCleaner.exe"))
{
    hash = SHA1.Create().ComputeHash(stream);
}
string base64Hash = Convert.ToBase64String(hash);
Console.WriteLine(base64Hash);

StreamWriter myWriter = new StreamWriter(@"C:\Users\Win7\Desktop\Hash.exe");
myWriter.Write(base64Hash);
4

3 回答 3

1

可执行文件的哈希码是字符串,不是有效的可执行文件。如果要存储哈希码,请将其写入文本文件,如下所示:

byte[] hash;
using (Stream stream = File.OpenRead(@"C:\Program files\CCleaner\CCleaner.exe"))
{
    hash = SHA1.Create().ComputeHash(stream);
}
string base64Hash = Convert.ToBase64String(hash);
Console.WriteLine(base64Hash);

StreamWriter myWriter = new StreamWriter(@"C:\Users\Win7\Desktop\Hash.txt");
myWriter.Write(base64Hash);
于 2013-08-05T03:10:03.440 回答
0

您需要了解什么是哈希算法。它不能用于您想要的。无法反转哈希以获取原始内容。那将是很棒的数据压缩。

于 2013-09-29T17:31:09.560 回答
0

The reason for this error:

I get the error: is not a valid win32 application

is that you are overwriting the beginning of the application. While you can append anything to most exe files, overwriting data is not going to work.

If you append the hash like this:

StreamWriter myWriter = new StreamWriter(@"C:\Users\Win7\Desktop\Hash.exe", true);

the application should run normally. Within this application, you can access the last bytes of the exe file to retrieve the hash.

于 2013-08-03T14:18:12.750 回答