Пример #1
0
 /// <summary>
 /// Recupera os bytes do identificador único.
 /// </summary>
 /// <param name="UID"></param>
 /// <returns></returns>
 public static byte[] GetUIDInBytes(string UID)
 {
     string[] _ids = UID.Split('-');
     if (_ids.Length != 4)
     {
         throw new ArgumentException("Wrong UID");
     }
     byte[] _value = new byte[16];
     Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[0])), 0, _value, 0, 8);
     Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[1])), 0, _value, 8, 8);
     Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[2])), 0, _value, 16, 8);
     Buffer.BlockCopy(BitConverter.GetBytes(BASE36.Decode(_ids[3])), 0, _value, 24, 8);
     return(_value);
 }
Пример #2
0
        /// <summary>
        /// Combine CPU ID, Disk C Volume Serial Number and Motherboard Serial Number as device Id
        /// </summary>
        /// <returns></returns>
        public static string GenerateUID(string appName)
        {
            string _id = string.Concat(appName, GetProcessorId(), GetMotherboardID(), GetDiskVolumeSerialNumber());

            byte[] _byteIds = Encoding.UTF8.GetBytes(_id);
            var    _md5     = new System.Security.Cryptography.MD5CryptoServiceProvider();

            byte[] _checksum = _md5.ComputeHash(_byteIds);
            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));

            return(string.Format("{0}-{1}-{2}-{3}", _part1Id, _part2Id, _part3Id, _part4Id));
        }