I think this may work.
public static byte[] StrToByteArray(string str)
{
Dictionary hexindex = new Dictionary();
for (int i = 0; i <= 255; i++)
hexindex.Add(i.ToString("X2"), (byte)i);
List hexres = new List();
for (int i = 0; i < str.Length; i += 2)
hexres.Add(hexindex[str.Substring(i, 2)]);
return hexres.ToArray();
}