Пример #1
0
        /// <summary>
        /// Encodes the specified <see cref="IDeviceIdComponent"/> as a string.
        /// </summary>
        /// <param name="component">The component to encode.</param>
        /// <returns>The component encoded as a string.</returns>
        public string Encode(IDeviceIdComponent component)
        {
            var value     = component.GetValue() ?? string.Empty;
            var bytes     = Encoding.UTF8.GetBytes(value);
            var algorithm = _hashAlgorithm.Invoke();
            var hash      = algorithm.ComputeHash(bytes);
            var output    = _byteArrayEncoder.Encode(hash);

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Returns the device identifier string created by combining the specified <see cref="IDeviceIdComponent"/> instances.
        /// </summary>
        /// <param name="components">A sequence containing the <see cref="IDeviceIdComponent"/> instances to combine into the device identifier string.</param>
        /// <returns>The device identifier string.</returns>
        public string GetDeviceId(IEnumerable <IDeviceIdComponent> components)
        {
            if (components == null)
            {
                throw new ArgumentNullException(nameof(components));
            }

            var value     = string.Join(",", components.OrderBy(x => x.Name).Select(x => x.GetValue()).ToArray());
            var bytes     = Encoding.UTF8.GetBytes(value);
            var algorithm = _hashAlgorithm.Invoke();
            var hash      = algorithm.ComputeHash(bytes);

            return(_byteArrayEncoder.Encode(hash));
        }
        /// <summary>
        /// Returns the device identifier string created by combining the specified <see cref="IDeviceIdComponent"/> instances.
        /// </summary>
        /// <param name="components">A sequence containing the <see cref="IDeviceIdComponent"/> instances to combine into the device identifier string.</param>
        /// <returns>The device identifier string.</returns>
        public string GetDeviceId(IEnumerable <IDeviceIdComponent> components)
        {
            if (components == null)
            {
                throw new ArgumentNullException(nameof(components));
            }

            var value = String.Join(",", components.OrderBy(x => x.Name).Select(x => x.GetValue()));

            var hash      = crypto.Security.ComputeHash(value, _salt);
            var hashbytes = Encoding.UTF8.GetBytes(hash);

            return(_byteArrayEncoder.Encode(hashbytes));
        }