private static byte[] FromHex(string hex)
{
string strippedHex = Strip(hex, "\t\r\n -");
if (strippedHex == null || strippedHex.Length % 2 != 0)
throw new FormatException("Invalid hexadecimal string");
byte[] result = new byte[ArraySize(strippedHex.Length / 2)];
for (int i = 0, j = 0; i < strippedHex.Length; i += 2, j++)
{
string s = strippedHex.Substring(i, 2);
result[j] = byte.Parse(s, NumberStyles.HexNumber);
}
return result;
}