public IActionResult Decrypt(string keyName, string keyId, [FromBody] ippw.EncryptedData encryptedData) { try { PrintRequestHeaders(); PrintUserClaims(); var decryptedData = keyManager.Decrypt(Request, keyName, keyId, encryptedData); return(Ok(decryptedData)); } catch (WebException ex) { var errorMessage = ""; using (var stream = ex.Response.GetResponseStream()) using (var reader = new StreamReader(stream)) { JObject json = JObject.Parse(reader.ReadToEnd()); errorMessage = (string)json.SelectToken("message"); } _logger.LogInformation("Error message : " + errorMessage); var wRespStatusCode = ((HttpWebResponse)ex.Response).StatusCode; if (wRespStatusCode == HttpStatusCode.Unauthorized) { _logger.LogInformation("Error in authroization header – sending unauthorized request to UKC. Use env UKC_USER / UKC_PASSWORD"); return(StatusCode(401, "Authroization failed – please check the request header credentials")); } return(StatusCode(400, "Invalid configuration or missing parameter. Check with system administrator")); } catch (UnboundKeyStore.Models.KeyAccessException) { return(StatusCode(403)); } catch (ArgumentException e) { _logger.LogInformation(e.ToString()); return(StatusCode(400, e.Message)); } }