Funcular.IdGenerators.Base36.Base36IdGenerator.ComputeHostHash C# (CSharp) Méthode

ComputeHostHash() public méthode

Base36 representation of the SHA1 of the hostname. The constructor argument numServerCharacters controls the maximum length of this hash.
public ComputeHostHash ( string hostname = null ) : string
hostname string
Résultat string
        public string ComputeHostHash(string hostname = null)
        {
            if (_hashBase36 != null)
                return _hashBase36;
            if (string.IsNullOrWhiteSpace(hostname))
                hostname = Dns.GetHostName()
                    ?? Environment.MachineName;
            string hashHex;
            using (var sha1 = new SHA1Managed())
            {
                hashHex = BitConverter.ToString(sha1.ComputeHash(Encoding.UTF8.GetBytes(hostname)));
                if (hashHex.Length > 14) // > 14 chars overflows int64
                    hashHex = hashHex.Substring(0, 14);
            }
            string hashBase36 = Base36Converter.FromHex(hashHex);
            _hashBase36 = hashBase36;
            if (_hashBase36.Length > this._numServerCharacters)
                _hashBase36 = _hashBase36.Substring(0, this._numServerCharacters);
            return _hashBase36;
        }