public static byte[] GetBytes(string hexString) { int num = 0; StringBuilder stringBuilder = new StringBuilder(); for (int index = 0; index < hexString.Length; ++index) { char c = hexString[index]; if (HexEncoding.IsHexDigit(c)) { stringBuilder.Append(c); } else { ++num; } } string str = stringBuilder.ToString(); byte[] numArray = new byte[str.Length / 2]; int index1 = 0; for (int index2 = 0; index2 < numArray.Length; ++index2) { string hex = new string(new char[2] { str[index1], str[index1 + 1] }); numArray[index2] = HexEncoding.HexToByte(hex); index1 += 2; } return(numArray); }