FileHash generator to match silverlight manifest

The above is the source of the below code.  I needed to use this to check that the generated Hash used in a silverlight manifest was indeed correct.  One of my customers was having trouble installing on a win7 64 bit system.  This same build works fine elsewhere.  In the end we used a different whitelabel (same code different graphics and therefore checksums).

using System;
using System.Security.Cryptography;
using System.IO;

namespace FileHashSample
{
public class FileHash
{
public FileHash()
{
return;
}

        public string ComputeHash(string filePath)
{
string filePathNormalized = System.IO.Path.GetFullPath(filePath);
SHA1 sha = new SHA1Managed();
FileStream fs = new FileStream(filePathNormalized, FileMode.Open, FileAccess.Read);
byte[] byteHash = sha.ComputeHash(fs);
fs.Close();
return Convert.ToBase64String(byteHash, 0, byteHash.Length);
}

        public static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine(“Please Enter a File Path”);
return;
}
string filePath = System.IO.Path.GetFullPath(args[0]);
FileHash objFileHash = new FileHash();
Console.WriteLine(“File Path is {0}”, filePath);
Console.WriteLine(“File Hash is {0}”, objFileHash.ComputeHash(filePath));
return;
}
}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s