private static byte[] DecryptHardwareUID(string UID) { //Split 4 part Id into 4 ulong string[] _ids = UID.Split('-'); //Combine 4 part Id into one byte array byte[] _value = new byte[16]; Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[0])), 0, _value, 0, 4); Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[1])), 0, _value, 4, 4); Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[2])), 0, _value, 8, 4); Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[3])), 0, _value, 12, 4); return(_value); }
public static string GenerateHardwareUid() { string hardwareUid = string.Empty; byte[] _checksum = GetHardwareUID(); //Convert checksum into 4 ulong parts and use BASE36 to encode both string _part1Id = BASE36.Encode(BitConverter.ToUInt32(_checksum, 0)); string _part2Id = BASE36.Encode(BitConverter.ToUInt32(_checksum, 4)); string _part3Id = BASE36.Encode(BitConverter.ToUInt32(_checksum, 8)); string _part4Id = BASE36.Encode(BitConverter.ToUInt32(_checksum, 12)); //Concat these 4 part into one string hardwareUid = string.Format("{0}-{1}-{2}-{3}", _part1Id, _part2Id, _part3Id, _part4Id); return(hardwareUid); }