public IActionResult Secure([FromBody] EncryptedPayload transmission, CancellationToken ct) { string raw; try { var key = Request.Headers["ghosts-name"].ToString(); //decrypt transmission.Payload = Base64Encoder.Base64Decode(transmission.Payload); raw = Crypto.DecryptStringAes(transmission.Payload, key); } catch (Exception exc) { log.Trace(exc); throw new Exception("Malformed data"); } //deserialize var value = JsonConvert.DeserializeObject <TransferLogDump>(raw); return(Process(HttpContext, Request, value, ct)); }
private static string CheckIfBase64Encoded(string raw) { var reg = new Regex("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$"); return(reg.IsMatch(raw) ? Base64Encoder.Base64Decode(raw) : raw); }