Member 13369156 Ответов: 1

Как мне получить MD5 файла и сравнить его


У меня возникли некоторые проблемы, когда я получаю md5 файла- - - - - > put it is a
if(a="ewfewf")
{
...}
но у меня есть некоторые ошибки.
Пожалуйста, помогите!

Что я уже пробовал:

ааааааааааааааааааааааааааааааааааааааааааааааааааааааааа

1 Ответов

Рейтинг:
11

raddevus

Вот код, который вы можете использовать для начала работы.
Если вы получите LINQPad - игровая площадка программиста .NET[^] вы можете поместить код в новый файл, запустить его и посмотреть результат.

void Main()
{
	// creating a temp file so the test will work on your machine.
        var tempFile1 = Path.GetTempFileName();
        // writing bytes which will be used to generate MD5 hash
	File.AppendAllText(tempFile1, "this is a test");
        // read all bytes of file so we can send them to the MD5 hash algo
	Byte [] allBytes = File.ReadAllBytes(tempFile1);
	System.Security.Cryptography.HashAlgorithm md5Algo = null;
	md5Algo = new System.Security.Cryptography.MD5CryptoServiceProvider();
        // compute the Hash (MD5) on the bytes we got from the file
	byte[] hash = md5Algo.ComputeHash(allBytes);
	Console.WriteLine(BytesToHex(hash));
      // output will be : 54B0C58C7CE9F2A8B551351102EE0938
     File.Delete(tempFile1);  // delete the temp file
      // Now you just need to do this for the second file and compare the strings.
	
}

private string BytesToHex(byte[] bytes) 
{ 
	// write each byte as two char hex output.
    return String.Concat(Array.ConvertAll(bytes, x => x.ToString("X2"))); 
}


Member 13369156

Большое спасибо!

[no name]

Спасибо за помощь!