[program-l] Re: Text file checksum code

  • From: "Jacob Kruger" <jacobk@xxxxxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Wed, 25 Mar 2009 11:04:03 +0200

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 code


If 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 code

Hi there

Currently 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

Other related posts: