Overview:
- I have a Outlook desktop add-in (extension) from which user can browse attachment.
- We call web API(c#) to upload that attachment data into azure blob storage.
- But I want that data to be encrypted (using AES with key and IV) into Outlook itself (That's working properly) and then pass to web API.
Questions:
- I tried passing data as a CryptoStream object. But It's not allowing to read CryptoStream. Is that possible to pass CryptoStream to web api ?
- Secondly I tried passing data as a
byte[]
(Byte Array) object. but that's again encrypted byte array. WhileHttpPostRequest
to API model validation fails. Is that possible to pass encrypted byte array to web api.
HttpPostRequest:
var content = new MultipartFormDataContent();
content.Add(new StringContent(encryptionKey.ToString()), nameof(ChannelMessageFilePostModel.EncryptionKey).ToCamelCase());
content.Add(new ByteArrayContent(encryptedBytes), nameof(ChannelMessageFilePostModel.EncryptedBytes).ToCamelCase());
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"ControllerName/MethodName/{id}");
request.Content = content;
return InvokeApi<ChannelMessageFileModel>(request, cancellationToken);
Post method Web API:
public async Task < IActionResult > Post(string Id, FilePostModel model) {
if (string.IsNullOrEmpty(Id) || model == null) {
return BadRequest();
}
//todo: check that ModelState is working for array
if (!ModelState.IsValid) {
return BadRequest(ModelState);
}
}
}
Here It fails on ModelState
for model.encryptedBytes
that is type of byte[]
.