internal string ComputeThrottleKey(RequestIdentity requestIdentity, RateLimitPeriod period) { var keyValues = new List <string>() { ThrottleManager.GetThrottleKey() }; if (Policy.IpThrottling) { keyValues.Add(requestIdentity.ClientIp); } if (Policy.ClientThrottling) { keyValues.Add(requestIdentity.ClientKey); } if (Policy.EndpointThrottling) { keyValues.Add(requestIdentity.Endpoint); } keyValues.Add(period.ToString()); var id = string.Join("_", keyValues); var idBytes = Encoding.UTF8.GetBytes(id); var hashBytes = new System.Security.Cryptography.SHA1Managed().ComputeHash(idBytes); var hex = BitConverter.ToString(hashBytes).Replace("-", string.Empty); return(hex); }
internal string ComputeThrottleKey(RequestIdentity requestIdentity, RateLimitPeriod period) { using (var ms = new MemoryStream()) using (var sw = new StreamWriter(ms, Encoding.UTF8)) { sw.Write(ThrottleManager.GetThrottleKey()); if (Policy.IpThrottling) { sw.Write(requestIdentity.ClientIp); } if (Policy.ClientThrottling) { sw.Write(requestIdentity.ClientKey); } if (Policy.EndpointThrottling) { sw.Write(requestIdentity.Endpoint); } sw.Write(period); sw.Flush(); ms.Position = 0; using (var algorithm = new SHA1Managed()) { var hash = algorithm.ComputeHash(ms); return(Convert.ToBase64String(hash)); } } }