Apart from that one, how would you then decode the info to get it back to normal text/XML?Hashes are one-way algos. This means that it can be used for integrety checking. Think of multiplying two prime numbers together. If you get the has of a file, and you multiply the two prime numbers, it's going to be really really hard to figure out which two prime numbers you multiplied, but the hash of the file will match. Md5 is usually used for this; I can download a file and compare it with it's md5 signature to make sure it hasn't:
been tampered with, or experienced loss of data on the wire. Thanks, Tyler Littlefield Web: tysdomain.com email: tyler@xxxxxxxxxxxxx My programs don't have bugs, they're called randomly added features.----- Original Message ----- From: "Jacob Kruger" <jacobk@xxxxxxxxxxxx>
To: <program-l@xxxxxxxxxxxxx> Sent: Wednesday, March 25, 2009 3:04 AM Subject: [program-l] Re: Text file checksum code
Ok, from the second one, this seems the simplest: public string GetMD5Hash(string input) {System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();byte[] bs = System.Text.Encoding.UTF8.GetBytes(input); bs = x.ComputeHash(bs); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in bs) { s.Append(b.ToString("x2").ToLower()); } string password = s.ToString(); return password; }Apart from that one, how would you then decode the info to get it back to normal text/XML?TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...'----- Original Message ----- From: "Mark Long" <markalong64@xxxxxxxxxxx>To: "Program-l" <program-l@xxxxxxxxxxxxx> Sent: Wednesday, March 25, 2009 10:43 AM Subject: [program-l] Re: Text file checksum codeIf the file is of arbitrary length then it can be padded to have the same checksum. This is called a forced collision.If you hashed it using two algorithms then it would be very much harder to do. I suggest that a sha1 and an MD5 would defeat most attackers.Sample code: http://dotnetpulse.blogspot.com/2007/12/sha1-hash-calculation-in-c.html http://blog.brezovsky.net/en-text-2.html Hope that helps Mark -------------------------------------------------- From: "Jacob Kruger" <jacobk@xxxxxxxxxxxx> Sent: Wednesday, March 25, 2009 7:53 AM To: "Program-l" <program-l@xxxxxxxxxxxxx> Subject: [program-l] Text file checksum codeHi thereCurrently looking into implementing a form of custom licensing system for some apps for work, and the one thing we might need to do is to use some form of checksum to make sure that the text/XML file to be used for storing licensing information hasn't been modified as such, so am currently looking for some sample code/examples related to doing this with text files since it doesn't as such seem to be naturally supported within the CLR framework/C#/VB.Net.Any ideas?Apart from that, here's a link to MS's own updated C# code samples file download page:http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=csharpsamples&ReleaseId=8 Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq