using System.Security.Cryptography;
using System.Collections.Generic;
public static void Main()
string input = "$080tomy";
Hash("Unicode", input, Encoding.Unicode);
Hash("Unicode big-endian", input, Encoding.BigEndianUnicode);
Hash("UTF-8", input, Encoding.UTF8);
Hash("Unicode custom", input, new UnicodeEncoding(true, false));
Console.WriteLine("utf-16");
data = Encoding.BigEndianUnicode.GetBytes(input);
Console.WriteLine(BytesToHex(Encoding.BigEndianUnicode.GetPreamble()));
Console.WriteLine(BytesToHex(data));
Console.WriteLine("from CF utf-16");
data = HexToBytes("FEFF00240030003800300074006F006D0079");
Console.WriteLine(Encoding.BigEndianUnicode.GetString(data));
Console.WriteLine("Final Solution");
byte[] mydata = Encoding.BigEndianUnicode.GetPreamble().Concat(Encoding.BigEndianUnicode.GetBytes(input)).ToArray();
using (MD5 md5Hash2 = MD5.Create())
byte[] myhash = md5Hash2.ComputeHash(mydata);
Console.WriteLine("HEX: {0}", BytesToHex(myhash));
Console.WriteLine("BASE64: {0}", Convert.ToBase64String(myhash));
private static void Hash(string mthod, string input, Encoding encoding)
Console.WriteLine(mthod);
using (MD5 md5Hash = MD5.Create())
byte[] data = md5Hash.ComputeHash(encoding.GetBytes(input));
Console.WriteLine("HEX: {0}", BytesToHex(data));
Console.WriteLine("BASE64: {0}", Convert.ToBase64String(data));
private static string BytesToHex(byte[] bytes)
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0:X2}", b);
private static byte[] HexToBytes(string hex)
List<byte> buff = new List<byte>();
for(int i = 0; i < hex.Length; i+= 2)
buff.Add(Byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber));