Hi, I have the following program working which will prove MD5 collisions for various files containing slightly different data. However, when I create the files using proven collision data from wikipedia
http://en.wikipedia.org/wiki/Md5[
^]I get hashes that do not match and neither of them match the correct hash of 79054025255fb1a26e4bc422aef54eb4. Yet with any other file (typically containing binary data) I am able to prove collisions.
The two inputs from the files are:
d131dd02c5e6eec4693d9a0698aff95c2fcab58712467eab4004583eb8fb7f89
55ad340609f4b30283e488832571415a085125e8f7cdc99fd91dbdf280373c5b
d8823e3156348f5bae6dacd436c919c6dd53e2b487da03fd02396306d248cda0
e99f33420f577ee8ce54b67080a80d1ec69821bcb6a8839396f9652b6ff72a70
and
d131dd02c5e6eec4693d9a0698aff95c2fcab50712467eab4004583eb8fb7f89
55ad340609f4b30283e4888325f1415a085125e8f7cdc99fd91dbd7280373c5b
d8823e3156348f5bae6dacd436c919c6dd53e23487da03fd02396306d248cda0
e99f33420f577ee8ce54b67080280d1ec69821bcb6a8839396f965ab6ff72a70
The program I'm using is below. Is there any way to alter this program to cater for these hex files or do I need to write a completely new one - I have seen solutions that look extremely complicated so I'm just wondering if the program below can be altered. Thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace MD53
{
class Program
{
static void Main(string[] args)
{
byte[] file1Hash = GetMd5HashOfFile("FileA.txt");
byte[] file2Hash = GetMd5HashOfFile("FileB.txt");
ConvertToString(file1Hash);
ConvertToString(file2Hash);
byte[] file3Hash = GetSHAOfFile("M13A.txt");
byte[] file4Hash = GetSHAOfFile("M13B.txt");
ConvertToString(file3Hash);
ConvertToString(file4Hash);
}
static byte[] GetMd5HashOfFile(string filepath)
{
using (MD5CryptoServiceProvider hashProvider = new MD5CryptoServiceProvider())
{
using (FileStream sr = new FileStream(filepath, FileMode.Open, FileAccess.Read))
{
return hashProvider.ComputeHash(sr);
}
}
}
static byte[] GetSHAOfFile(string filepath)
{
using (SHA1CryptoServiceProvider hashProvider = new SHA1CryptoServiceProvider())
{
using (FileStream sr = new FileStream(filepath, FileMode.Open, FileAccess.Read))
{
return hashProvider.ComputeHash(sr);
}
}
}
static void ConvertToString(byte[] fileHash)
{
StringBuilder hex1 = new StringBuilder(fileHash.Length);
foreach (byte b in fileHash)
hex1.AppendFormat("{0:x2}", b);
string output = hex1.ToString();
Console.WriteLine(output);
return;
}
}
}