Need an API for flushing additional stuff at the end of PipeWriter. #26047
Replies: 6 comments 3 replies
-
Can you clarify what exactly you're trying to do with a running code sample? |
Beta Was this translation helpful? Give feedback.
-
I am following https://tudip.com/blog-post/how-to-securely-transfer-web-api-data-in-asp-net-core/ blog for Encrypting and Decrypting all the incoming and outgoing traffic using Middleware. While encrypting data in Aes data need's to be a fixed size block.
|
Beta Was this translation helpful? Give feedback.
-
Why aren't you using https instead? |
Beta Was this translation helpful? Give feedback.
-
To protect our JSON schema. |
Beta Was this translation helpful? Give feedback.
-
I don't know if this approach makes any sense (cc @blowdart), but to answer your question about when to call FlushFinalBlock:
app.Use(async (httpContext, next) =>
{
var oldResponse = httpContext.Response.Body;
var oldRequest = httpContext.Request.Body;
try
{
await using var newResponseBody = EncryptStream(oldResponse);
await using var newRequestBody = DecryptStream(oldRequest );
httpContext.Response.Body = newResponseBody;
httpContext.Request.Body = newRequestBody;
await next();
}
finally
{
httpContext.Response.Body = oldResponse;
httpContext.Request.Body = oldRequest;
}
}); The code above made some tweaks to the original code to dispose the crypto stream when complete (using IAsyncDisposable and await using) |
Beta Was this translation helpful? Give feedback.
-
Getting exception after calling await next();
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In Aes encryption we need to add padding at the end of stream by calling CryptoStream.FlushFinalBlock() https://stackoverflow.com/a/40564155/2949571
I can't find any api to do that via PipeWriter/BodyWriter in asp.net core.
Issue is that client side I am receiving encrypted data without padding. So client side is not able to decrypt the data.
@davidfowl
Beta Was this translation helpful? Give feedback.
All reactions