Example #1
0
        /// <summary>
        /// Gets the hardware identifier for the current computer.
        /// NOTE: <see cref="SetComputerCharacteristics(IComputerCharacteristics)"/> must be set before using this method.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotSupportedException">
        /// Thrown if <see cref="SetComputerCharacteristics(IComputerCharacteristics)"/> was not set before.
        /// </exception>
        public static string ForCurrentComputer()
        {
            if (theComputerCharacteristics == null)
            {
                throw new NotSupportedException("Creating hardware id for current computer is not supported for DotNetStandard. Please use 'HardwareIdentifier.SetComputerCharacteristics' to set a plattform specific implementation of 'IComputerCharacteristics'.");
            }

            var encodedCharacteristics = new List <string>();

            foreach (var characteristic in theComputerCharacteristics.GetCharacteristicsForCurrentComputer())
            {
                var bytes = Encoding.UTF8.GetBytes(characteristic);
                bytes = MD5.ComputeHash(bytes);

                encodedCharacteristics.Add(Encoder.Encode(bytes));
            }

            var hardwareKey = string.Join(Separator, encodedCharacteristics);

            return(CheckSumAppender.Append(hardwareKey));
        }