static string GetHex16(string strText)
if (!string.IsNullOrEmpty(strText))
byte[] byteContents = Encoding.Unicode.GetBytes(strText);
System.Security.Cryptography.SHA256 hash = new System.Security.Cryptography.SHA256CryptoServiceProvider();
byte[] hashText = hash.ComputeHash(byteContents);
Int64 hashCodeStart = BitConverter.ToInt64(hashText, 0);
Int64 hashCodeMedium = BitConverter.ToInt64(hashText, 8);
Int64 hashCodeEnd = BitConverter.ToInt64(hashText, 24);
hashCode = hashCodeStart ^ hashCodeMedium ^ hashCodeEnd;
return hashCode.ToString("X16");
static bool IsHexString(string s)
static string GetHex20(string strText, string prefix)
if (prefix.Length != 4 || !IsHexString(prefix))
throw new System.ArgumentException("Prefix '" + prefix + "' must be hex string of length 4.");
return prefix.ToUpper() + GetHex16(strText);
public static void Main()
Console.WriteLine(GetHex20(" ", "00aa"));