[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2831
  • Last Modified:

how to implement file checksum ?

Guyz,

My application uses a .xml file as input, and I need to make sure nobody has edited the file. Can we implement a checksum for this file? If so,
1.Where do I specify the file checksum in the .xml file
2.How to calculate the checksum for the .xml file and compare with the checksum found in the .xml file.

Any ideas?
Thnx!
0
kunjachan_
Asked:
kunjachan_
  • 4
  • 3
1 Solution
 
TheAvengerCommented:
You can create the file, then calculate the sum (for example getting the hash of the whole file string or only a part of it which is important) and save the check sum at the end of the file. When you read it, you can read the whole file, get the check sum that was saved inside it and then calculate again the checksum for the rest of the file (so the real contents, which was also secured when the file was saved). Then compare the check sums.

Instead of calculating a check sum, you can use a more advanced method, like sign the data. For more info have a look at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconCryptographicServices.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecuritycryptographydsaclasstopic.asp
0
 
psdavisCommented:
I like using MD5 for my checksums.

            MD5 pMD5 = new MD5CryptoServiceProvider( );
            byte[] resultHash = pMD5.ComputeHash( Encoding.ASCII.GetBytes( response ));
            string resultMD5 = Convert.ToBase64String( resultHash );
0
 
TheAvengerCommented:
Note that using MD5 you can create a hash but you cannot sign it, so everybody can create the hash after signing the file
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
psdavisCommented:
If all he is doing is making sure no one has edited the file, then the checksum idea is sound.  His biggest problem is that he wants to include the checksum inside the xml which invariably changes the checksum of the file.
0
 
TheAvengerCommented:
First, if I change the file, I will calculate a new hash, so the application will not notice that the file was changed - the hash is not enough.
Second, I already explained how the hash/signature can be included inside the file: make the hash always over the XML without the hash. This means you have <xml content><hash> and when the file is read, you remove the <hash> part, make a new hash of the <xml content> and verify the new hash with the <hash> part.
0
 
psdavisCommented:
Yep. Yer right.  I'm still pre-Diet Pepsi and not fully awake yet.
0
 
TheAvengerCommented:
:-))
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now