private static byte[] StringToByteArray(string hex) {
if (hex.Length % 2 == 1) {
throw new ArgumentException("The binary key cannot have an odd number of digits");
}
byte[] arr = new byte[hex.Length >> 1];
for (int i = 0; i < (hex.Length >> 1); ++i) {
arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + GetHexVal(hex[(i << 1) + 1]));
}
return arr;
}