I have an API endpoint that has a "hash" key that is sent via the HTTPheader request. When then end point is hit I need to compare the hash key from the header to the hash key on my end point as follows
public async Task<ResponseHandler> test([FromBody] Command command)
{
if (Request.Headers.ContainsKey("hash") ? Request.Headers.TryGetValue("hash", out var hash) : throw new InvalidOperationException())
{
using (var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes("some key")))
using (var memoryStream = new MemoryStream()) //fails
{
await Request.Body.CopyToAsync(memoryStream);
memoryStream.Position = 0;
if (Convert.ToBase64String(hmacsha256.ComputeHash(memoryStream.ToArray())) != hash)
throw new Exception();
}
}
}
but when it hits the memory stream it fails and gives me an error
'memoryStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException' 'memoryStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'
what am I doing wrong?