C# Md5 vs MD5sum

C

chis2k

I am trying to figure out how to get the MD5 sum of a file that is like the
result from the MD5sum.exe program that is readily available on the
internet. I tried the following but it gives me something completely
different.... Any ideas?

MD5sum.exe output = c37a2719bd83ba766b29d8f83cee6258
My program output = w3onGb2DunZrKdj4PO5iWA==

public string GetMD5Hash( byte[] input_buffer) {
// create implementation of MD5
MD5 md5 = new MD5CryptoServiceProvider();
// get hash
return System.Convert.ToBase64String(md5.ComputeHash(input_buffer));
}
 
J

Jon Skeet

chis2k said:
I am trying to figure out how to get the MD5 sum of a file that is like the
result from the MD5sum.exe program that is readily available on the
internet. I tried the following but it gives me something completely
different.... Any ideas?

MD5sum.exe output = c37a2719bd83ba766b29d8f83cee6258
My program output = w3onGb2DunZrKdj4PO5iWA==

public string GetMD5Hash( byte[] input_buffer) {
// create implementation of MD5
MD5 md5 = new MD5CryptoServiceProvider();
// get hash
return System.Convert.ToBase64String(md5.ComputeHash(input_buffer));
}

You're assuming that the result of MD5sum is the Base64 result - it
looks more like hex to me. Indeed, if you try the following program
which converts your base64 to hex, you'll see a familiar sequence...

using System;

public class Test
{
static void Main()
{
byte[] md5 = Convert.FromBase64String
("w3onGb2DunZrKdj4PO5iWA==");
Console.WriteLine (BitConverter.ToString(md5));
}
}
 
C

chis2k

Thanks! That was it!

Jon Skeet said:
chis2k said:
I am trying to figure out how to get the MD5 sum of a file that is like the
result from the MD5sum.exe program that is readily available on the
internet. I tried the following but it gives me something completely
different.... Any ideas?

MD5sum.exe output = c37a2719bd83ba766b29d8f83cee6258
My program output = w3onGb2DunZrKdj4PO5iWA==

public string GetMD5Hash( byte[] input_buffer) {
// create implementation of MD5
MD5 md5 = new MD5CryptoServiceProvider();
// get hash
return System.Convert.ToBase64String(md5.ComputeHash(input_buffer));
}

You're assuming that the result of MD5sum is the Base64 result - it
looks more like hex to me. Indeed, if you try the following program
which converts your base64 to hex, you'll see a familiar sequence...

using System;

public class Test
{
static void Main()
{
byte[] md5 = Convert.FromBase64String
("w3onGb2DunZrKdj4PO5iWA==");
Console.WriteLine (BitConverter.ToString(md5));
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top