Geeks With Blogs
An educated guess (Timur Fanshteyn) Technology, Software Development and other ways to make an educated guess about the world...

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

Posted on Thursday, December 20, 2007 10:50 PM | Back to top


Comments on this post: Calculating Hashvalues for files the way .NET does for the Application Manifest

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Timur Fanshteyn | Powered by: GeeksWithBlogs.net