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;
}