public ActionResult <EncryptDecryptModel> GetCipherText(EncryptDecryptModel model) { try { if (string.IsNullOrEmpty(model.plainText) && string.IsNullOrEmpty(model.cipherText)) { return(NoContent()); } string original = model.plainText; using (AesCryptoServiceProvider myAes = new AesCryptoServiceProvider()) { //myAes.GenerateKey(); myAes.Key = Convert.FromBase64String(_configKey); // Encrypt the string to an array of bytes. string cipherText = EncryptString(original, myAes.Key); string decryptedPlaintText = DecryptString(cipherText, myAes.Key); model.cipherText = cipherText; } return(Ok(model)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public IActionResult Index(EncryptDecryptModel EncDecModel) { EncryptDecryptModel newModel = new EncryptDecryptModel(); SecurityController securityController = new SecurityController(_configuration); newModel.plainText = EncDecModel.plainText; newModel.cipherText = EncDecModel.cipherText; if (EncDecModel.plainText == null && EncDecModel.cipherText == null) { return(View()); } else if (EncDecModel.plainText != null && EncDecModel.cipherText != null) { return(View(EncDecModel)); } else if (EncDecModel.plainText != null && EncDecModel.cipherText == null) { newModel.cipherText = securityController.ObtainCipherText(EncDecModel.plainText); } else if (EncDecModel.plainText == null && EncDecModel.cipherText != null) { newModel.plainText = securityController.ObtainPlaintText(EncDecModel.cipherText); } return(View(newModel)); }
public ActionResult <EncryptDecryptModel> GetPlaintext(EncryptDecryptModel model) { try { using (AesCryptoServiceProvider aesAlg = new AesCryptoServiceProvider()) { aesAlg.Key = Convert.FromBase64String(_configKey); string b64CipherText = model.cipherText; string decryptedTxt = DecryptString(b64CipherText, aesAlg.Key); model.plainText = decryptedTxt; return(Ok(model)); } } catch (Exception ex) { //TODO: Write to EventLog, Alert Error return(StatusCode(500, ex)); } }
public static async Task <string> MethodToMakeInitialAPICall() { using (HttpClient httpClient = new HttpClient()) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); Uri baseAddress = new Uri(config["EncryptDecryptService"]); httpClient.BaseAddress = baseAddress; EncryptDecryptModel model = new EncryptDecryptModel(); model.cipherText = config["Encrypted_String"]; string jsonInput = JsonConvert.SerializeObject(model); HttpContent content = new StringContent(jsonInput, System.Text.Encoding.UTF8, "application/json"); string requestEndPoint = "api/Security/decrypt"; HttpResponseMessage httpResponse = await httpClient.PostAsync(requestEndPoint, content).ConfigureAwait(true); string response = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(true); EncryptDecryptModel encryptDecryptModel = JsonConvert.DeserializeObject <EncryptDecryptModel>(response); return(encryptDecryptModel.plainText); } }
public IActionResult Index() { EncryptDecryptModel encryptDecryptModel = new EncryptDecryptModel(); return(View(encryptDecryptModel)); }