private static byte[] HexToByteArray(string hexString)
{
if (hexString.Length % 2 != 0)
throw new FormatException();
var bytes = new byte[hexString.Length / 2];
for (int i = 0; i < bytes.Length; i++)
bytes[i] = byte.Parse(hexString.Substring(i * 2, 2), NumberStyles.HexNumber);
return bytes;
}