Home
Manage Your Code
Snippet: String hashcode from byte array (C#)
Title: String hashcode from byte array Language: C#
Description: Handy for generating a unique (ish) filename from a file or array of bytes Views: 109
Author: Als James Date Added: 11/11/2008
Copy Code  
1  	/// <summary>
2        /// Generates a hashcode for use as a filename from the given byte array
3        /// </summary>
4        public static String GenerateHashcodeFilename(Byte[] byteArray)
5        {
6            Byte[] hashVal = new MD5CryptoServiceProvider().ComputeHash(byteArray);
7
8            StringBuilder sb = new StringBuilder();
9
10            foreach (Byte b in hashVal)
11            {
12                sb.Append(b.ToString("X2"));
13            }
14
15            return String.Format("{0}", sb.ToString());
16        }