An educated guess (Timur Fanshteyn)

Technology, Software Development and other ways to make an educated guess about the world...

  Home  |   Contact  |   Syndication    |   Login
  17 Posts | 0 Stories | 4 Comments | 0 Trackbacks

News

Twitter












Tag Cloud


Archives

I had to write a custom download component to download modules for a ClickOnce deployed application. The actual downloading is simple, the tricky part was creating the manifest and make sure that I only download files that are required.

I am using an GeneraApplicationManifest MSBuild task to generate an application manifest. The documentation is very easy to follow.

The generated manifest will include a Hash value. It is fairly simple to compute the same hash value manually and be able to validate it.

private bool HashChanged(string fileName, string originalHashValue)
        {
            byte[] Hash = Convert.FromBase64String(originalHashValue));
            byte[] newHash;
            SHA1Managed sha = new SHA1Managed();
            
            FileStream strm = null;
            try
            {
                strm = new FileStream(fileName, FileMode.Open, FileAccess.Read);            
                newHash = sha.ComputeHash(strm);
            }
            finally
            {
                if (strm != null)
                    strm.Close();
            }

            if (Hash.Length != newHash.Length)
                return true;
            for(int i = 0; i< Hash.Length; i++)
            {
                if (Hash[i] != newHash[i])
                    return true;
            }
            return false;
        }
Technorati Tags: ,,,

Cross Posted from http://blog.tfanshteyn.com/2007/12/calculating-hashvalues-for-files-way.html

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Thursday, December 20, 2007 10:50 PM