private static string GetContent(byte[] secret, HttpListenerRequest request) { var ms = new System.IO.MemoryStream(); request.InputStream.CopyTo(ms); byte[] bytes = ms.ToArray(); (request.InputStream as IDisposable).Dispose(); var signature = request.Headers.Get("X-Signature"); if (secret != null) { using (var hmac = new System.Security.Cryptography.HMACSHA1(secret)) { hmac.Initialize(); string result = BitConverter.ToString( hmac.ComputeHash(bytes, 0, bytes.Length) ).Replace("-", ""); if (!string.Equals( signature, $"sha1={result}", StringComparison.OrdinalIgnoreCase )) { return(null); } } } return(request.ContentEncoding.GetString(bytes)); }
public static string HMACSHA1(string text, string passKey) { var provider = new System.Security.Cryptography.HMACSHA1(Encoding.ASCII.GetBytes(passKey)); provider.Initialize(); var binary = provider.ComputeHash(Encoding.ASCII.GetBytes(text)); return(Convert.ToBase64String(binary)); }
private string CreateHubSignature(string bodyMessage) { var hashResult = string.Empty; using (var hmac = new System.Security.Cryptography.HMACSHA1(Encoding.UTF8.GetBytes(_appSecret))) { hmac.Initialize(); var hashArray = hmac.ComputeHash(Encoding.UTF8.GetBytes(bodyMessage)); var hash = $"SHA1={BitConverter.ToString(hashArray).Replace("-", string.Empty)}"; hashResult = hash; } return(hashResult); }
public byte[] ComputeHash(byte[] data, int offset, int length) { _algorithm.Initialize(); return(_algorithm.ComputeHash(data, offset, length)); }
public byte[] Calc(byte[] data) { _algorithm.Initialize(); return(_algorithm.ComputeHash(data)); }