public static ByteArray ToByteArray(string str) { if (!IsUid(str)) return null; str = str.Replace("-", ""); var ret = new ByteArray(); for (int i = 0; i < str.Length; i += 2) { byte num; if (!byte.TryParse(str.Substring(i, 2), NumberStyles.HexNumber, null, out num)) return null; ret.WriteByte(num); } ret.Position = 0; return ret; }