Click here to Skip to main content
15,885,914 members
Home / Discussions / C#
   

C#

 
GeneralRe: drag and drop Pin
molesworth19-Jun-09 4:44
molesworth19-Jun-09 4:44 
QuestionList to xml Pin
zeeShan anSari19-Jun-09 3:44
zeeShan anSari19-Jun-09 3:44 
AnswerRe: List to xml Pin
harold aptroot19-Jun-09 3:52
harold aptroot19-Jun-09 3:52 
GeneralRe: List to xml Pin
zeeShan anSari19-Jun-09 4:08
zeeShan anSari19-Jun-09 4:08 
GeneralRe: List to xml Pin
harold aptroot19-Jun-09 4:13
harold aptroot19-Jun-09 4:13 
GeneralRe: List to xml Pin
zeeShan anSari19-Jun-09 4:25
zeeShan anSari19-Jun-09 4:25 
GeneralRe: List to xml Pin
harold aptroot19-Jun-09 4:33
harold aptroot19-Jun-09 4:33 
QuestionFile Byte[] Conversion to String for MD5 Hash Generation Pin
JimmyHeaddon19-Jun-09 3:39
JimmyHeaddon19-Jun-09 3:39 
Hello!

I am trying to write an app that will read a file and generate an RFC 1321 compliant MD5 hash.

I have read a number of tutorials online and have been able to generate a compliant MD5 hash from a string, but I need to be able to pass my app a file and say "what is the MD5 hash of this file?".

Apparently I can read the file in to a byte array and then convert this to a string that my MD5 hash generator can read.


So far I have hit 2 problems:

- My byte[] conversion to string is resulting in an incorrect MD5 hash to all the web generators I have tried.
- I cannot read the byte[] of a file over 2 gigabytes (a buffering is needed I'm told?).


Any chance someone could help me out here? Ignore the part where I am setting the textbox.text value this was just for debug!

private void button1_Click(object sender, EventArgs e) {
   // Read File byte[] And Convert To String
   Byte[] byteArray = File.ReadAllBytes("C:\\ITV-9C-28225-C.xml");
   String stringFromByteArray = Convert.ToBase64String(byteArray);

   // Return The MD5 Hash Value
   textBox2.Text = MD5Hash(stringFromByteArray);
}

// Generate MD5 Hash Value
public static string MD5Hash(string text) {
   System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
   return System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(md5.ComputeHash(ASCIIEncoding.Default.GetBytes(text))), "-", "");
}



Cheers in advance!
AnswerRe: File Byte[] Conversion to String for MD5 Hash Generation Pin
harold aptroot19-Jun-09 3:45
harold aptroot19-Jun-09 3:45 
AnswerRe: File Byte[] Conversion to String for MD5 Hash Generation [modified] Pin
Mirko198019-Jun-09 4:02
Mirko198019-Jun-09 4:02 
AnswerRe: File Byte[] Conversion to String for MD5 Hash Generation Pin
JimmyHeaddon19-Jun-09 4:27
JimmyHeaddon19-Jun-09 4:27 
AnswerRe: File Byte[] Conversion to String for MD5 Hash Generation Pin
Luc Pattyn19-Jun-09 4:02
sitebuilderLuc Pattyn19-Jun-09 4:02 
Questionconnection string in a file Pin
Adekolurejo19-Jun-09 3:38
Adekolurejo19-Jun-09 3:38 
AnswerRe: connection string in a file Pin
SeMartens19-Jun-09 3:44
SeMartens19-Jun-09 3:44 
AnswerRe: connection string in a file Pin
stancrm19-Jun-09 3:47
stancrm19-Jun-09 3:47 
GeneralRe: connection string in a file Pin
harold aptroot19-Jun-09 4:00
harold aptroot19-Jun-09 4:00 
GeneralRe: connection string in a file Pin
Adekolurejo19-Jun-09 4:30
Adekolurejo19-Jun-09 4:30 
GeneralRe: connection string in a file Pin
harold aptroot19-Jun-09 4:34
harold aptroot19-Jun-09 4:34 
AnswerRe: connection string in a file Pin
meeram39519-Jun-09 3:48
meeram39519-Jun-09 3:48 
AnswerRe: connection string in a file [modified] Pin
kstls20-Jun-09 11:03
kstls20-Jun-09 11:03 
QuestionUrgent Mail Sending Problem Pin
dev sheoran19-Jun-09 2:09
dev sheoran19-Jun-09 2:09 
AnswerRe: Urgent Mail Sending Problem Pin
Not Active19-Jun-09 2:13
mentorNot Active19-Jun-09 2:13 
GeneralRe: Urgent Mail Sending Problem Pin
dev sheoran19-Jun-09 2:30
dev sheoran19-Jun-09 2:30 
GeneralRe: Urgent Mail Sending Problem Pin
Nagy Vilmos19-Jun-09 3:22
professionalNagy Vilmos19-Jun-09 3:22 
JokeRe: Urgent Mail Sending Problem [modified] Pin
musefan19-Jun-09 3:24
musefan19-Jun-09 3:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.